3 comments

[ 4.2 ms ] story [ 18.1 ms ] thread
The python test could've been a bit better if the code was in a main function.

Outside of that, node is based on v8 which is a billion dollar project to make single-threaded execution as fast as possible to handle all ads Google can trow at a user at a time.

> The python test could've been a bit better if the code was in a main function.

Interesting. Didn't try that. I'll give it a go.

And yes, NodeJS is a massive project compared to Python. But I think the performance difference, has at least something to do with language design. Javascript is more primitive language than Python so it is much easier to write a really fast interpreter for it.

The main function vs script difference is due to search in the name spaces of a function and global. The function is a tiny array, while the global one is a dictionary with the need of hashing and possible collision resolution. Do it enough times and it shows.

The relative slowness is not unexpected. A stated non-goal of python is speed optimization. If you need such, you can try with pypy. At the same time, Node is purely performance driven and the jit compiler there is tuned for this.