3 ms·
I'd recommend checking out numba (https://pypi.org/project/numba/ https://pypi.org/project/numba/) - where relevant, it can give huge speedups for minimal effor
by Ukv 2y ago
I'd recommend checking out numba (https://pypi.org/project/numba/ https://pypi.org/project/numba/) - where relevant, it can give huge speedups for minimal effort.
Just adding @numba.njit above the factorial function gives me a 36X speedup, putting it ahead of PyPy/Node.js and just a couple of times slower than Rust.
- frontalier 2y agono need to bring numba into this when functools is right there time python fibo.py 999 999 26863810024485359386146727202142923967616609318986952340123175997617981700247881689338369654483356564191827856161443356312976673642210350324634850410377680367334151172899169723197082763985615764450078474174626 python fibo.py 999 0.04s user 0.03s system 39% cpu 0.180 total
- Ukv 2y agoTrue that memoization makes factorial trivial, but I think that's erring on the side of skipping the computation we're meant to be benchmarking; a pre-computed array may be even faster. Numba's JIT is applicable in a wide range of scenarios, and could be used alongside memoization if needed.
- crustycoder 2y agoExcept of course that's completely missing the point of the benchmark - not that it is a good point, admittedly.
- frontalier 2y ago> not that it is a good point thank you