5 ms·
Javascript being 41x faster than Python seems a bit excessive. In my experience, having done quite a lot of dynamic language benchmarks, Javascript is about as
by Timja 4y ago
Javascript being 41x faster than Python seems a bit excessive.
In my experience, having done quite a lot of dynamic language benchmarks, Javascript is about as fast as PHP and both are about 6x faster than Python.
Has someone looked at the Python code used here, if it has any obvious gotchas?
- brrrrrm 4y agolet me know if you find anything! Happy to edit the post with a correction. For a little more information, this is using Bun 0.2.1, which uses JavaScriptCore (JSC), a part of WebKit which powers Safari. Since I'm running on an M1 Pro (Apple's ARM chip), there is probably somewhat of a benefit in using JSC.
- Spivak 4y agoIt’s a benchmark that is basically the ideal case for a JIT so it’s really Python vs. JS that got native compiled. I’m in no way criticizing the benchmark but that’s the reason for the starker difference.
- pedrovhb 4y agoThere is one. The author's implementation of `combinations` runs in quadratic time making copies of lists on each iteration. I replaced that for `itertools.combinations`, which uses an iterator, and found a pretty big difference: ~/p/not_that_slow python3.11 modified.py 5000000 -0.169075164 0.183753791 Time: 6.335 s ~/p/not_that_slow python3.11 main.py 5000000 -0.169075164 -0.169083134 Time: 48.515 s Other than this, the only modification I made is to include a `print` statement at the end to show the time taken. EDIT: That is not actually equivalent, my bad. The iterator is consumed and the execution ends early, I didn't realize the algorith iterated over it multiple times.
- IshKebab 4y agoIt's not excessive in my experience. Javascript is usually very fast. Much faster than PHP and Phython. There are many flaws in this benchmark but the order of magnitude looks right to me: https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/python.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/...