niklas-heer / speed-comparison

A repo which compares the speed of different programming languages.
https://niklas-heer.github.io/speed-comparison
MIT License
508 stars 79 forks source link

PRF: only get the odd numbers from range in Python #41

Closed tacaswell closed 2 years ago

tacaswell commented 2 years ago

This eliminates a muliplication and an addition in the hot loop.

Also explicit make all the literals floats which will marginally help with py311+.

Moelf commented 2 years ago

I still think this is technically cheating, because other languages probably don't optimize the muladd outside the loop, but idk

niklas-heer commented 2 years ago

I think it is probably fine. It closes the gap a little bit with CPython, but it is not changing things too wildly. PyPy actually benefits the most. combined_results

niklas-heer commented 2 years ago

Thank you for your contribution @tacaswell 👍