In fact, it is not possible to set up such a benchmark and get results useful enough to create complete speed statements; benchmarking is extremely complex, and in some cases, battery life can even partially separate parts of your test because they understand that there is a faster way to do what you say you want to do.
However, in the end, you are not comparing Python with node.js, you are comparing their interpreters: CPython with V8. Python and Javascript have similar language features that affect performance (garbage collection, dynamic types, even heap allocation of integers, which I think?), So when you run this test, it really is a shootout between translators.
And in this context, although such tests, as a rule, have no value, the question βWhy is V8 faster than CPython for this kind of thingβ has a kind of answer: because of the JIT compiler .
So, if you want a direct comparison, try running your Python code on PyPy, which is a Python interpreter with JIT. Or try running Javascript code at runtime without JIT. However, at this point, you will probably find that benchmarking is too complex and too complex to use a script like this to judge which language is faster.
Andrew Gorcester
source share