dennisbakhuis / python3.11_speedtest

Simple speed tests for Python 3.11
MIT License
61 stars 19 forks source link

even faster with Cython! #7

Closed sjev closed 1 year ago

sjev commented 1 year ago

I just could not leave it alone... that C guy should have a reason to shut up... Added Cython to the equation, resulting function is faster than current C implementation. (ok, I may have removed a division, but anyway)

C:

Pi is approximately 3.13878 and took 0.07303 seconds to calculate.
Pi is approximately 3.14086 and took 0.07647 seconds to calculate.
Pi is approximately 3.1403 and took 0.07498 seconds to calculate.
Pi is approximately 3.14166 and took 0.07627 seconds to calculate.
Pi is approximately 3.14396 and took 0.07133 seconds to calculate.
Test run was done with 1.00e+06 points.
Each loop took on average 0.07442 seconds to calculate.

cython:

(venv) jev@viviobook:~/Development/python3.11_speedtest$ ./single_test_run.py --jit cython
('Final Estimation of Pi=', 3.14252)
('Final Estimation of Pi=', 3.143036)
('Final Estimation of Pi=', 3.140736)
('Final Estimation of Pi=', 3.140328)
('Final Estimation of Pi=', 3.143228)
Test run was done with n_points=1.00e+06
Estimating pi took 0.0457 seconds per run.