Python, Go, and Rust code for comparing execution time.
Each implementation is split into 3 files:
- functions: functions to read rate files, produce a collection of rates for a specific case, run an illustration, and solve for a premium
- parallel: architecture to run multiple cases over multiple workers using a queue or queue-like system
- main: primary entry point for benchmarking both an illustration simulation and a premium solve simulation
Tested on Python versions 3.14.2, 3.13.11, 3.12.10, 3.11.9
For associated Excel model, download here: https://www.carractuarial.com/s/Carr-Actuarial-UL-Illustration-Model-For-Speed-Benchmark.xlsm
Enter "python" subdirectory, create and launch virtual environment, install requirements, and run main.py for run time results, e.g.
python -m venv venv
venv/scripts/activate
pip install -r requirements.txt
python main.py
Adjust N and W in main.py to adjust cases and # of parallel processes.
Enter "go" subdirectory and run main.go for benchmarking results
go run .
Adjust numTasks and numWorkers in main.go to adjust cases and # of parallel processes.
To build an executable use this command instead:
go build .
Exe that is generated by go build . can be successfully run in the "go" subdirectory it is generated in. Relative references are used which may cause the exe to fail in other locations.
Enter "rust" subdirectory and run using cargo
For running in debug mode (faster compilation, slower execution):
cargo run .
For running release (slower compilation, faster execution)
cargo run --release .
The exe that is generated by cargo run --release . must be exected from the "rust" subdirectory due to relative references in the code otherwise it will fail.