Node.js 14 is over 20x faster than Python3.8 for fib(n)

These are the versions I had lying around on my laptop.

Obviously this isn't the most comprehensive benchmark, but the results are surprising to me.

# (Python 3.8.2)
import time

def fib(n):
  if n == 1 or n == 0:
    return 1
  return fib(n - 1) + fib(n - 2)

t0 = time.time()
fib(35)
t1 = time.time()
print(f"{(t1 - t0) * 1000} ms")

2021.4319229125977 ms

// (Node.js v14.15.4)
const {
  performance
} = require('perf_hooks');

function fib(n) {
  if (n === 1 || n === 0) {
    return 1;
  }
  return fib(n - 1) + fib(n - 2);
}

const t0 = performance.now();
fib(35);
const t1 = performance.now();
console.log(`${t1 - t0} ms`);

86.51808297634125 ms




A discussion on HN can be found here: https://news.ycombinator.com/item?id=26079570