5 ms·
1. Python doesn't have a JIT. This shouldn't be surprising or headline worthy. 2. Why benchmark an O(2^n) fibonacci? It's basically benchmarking call frame c
by davesque 6y ago
1. Python doesn't have a JIT. This shouldn't be surprising or headline worthy.
2. Why benchmark an O(2^n) fibonacci? It's basically benchmarking call frame creation.
3. A single order of magnitude is honestly not that impressive a speedup for JIT vs. no JIT. Might have a lot to do with the inefficiency of the recursive fibonacci func.
Also, to quote another poster:
@numba.njit
def fib(n):
if n == 1 or n == 0:
return 1
return fib(n - 1) + fib(n - 2)
After JIT warms up:
~86 ms
Which is...effectively identical to Node?
- masklinn 6y ago> Which is...effectively identical to Node? You'd have to also run the node version on your machine to know, as it's unlikely you have the exact same setup as TFA.
- contravariant 6y agoOf course in the category of 'single line' performance optimizations the most effective one is going to be: @lru_cache(1000) def fib(n): if n == 1 or n == 0: return 1 return fib(n - 1) + fib(n - 2) which lowers the time to somewhere around 20 microseconds. I'd be interested to know if Node.js can do anything similar.