Live data from Hacker News

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

jott.live

51–60 of 119 posts

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

#51

Earlier quoted context omitted.

> An interpreter with a JIT is obviously faster than one without. And why doesn't python's default runtime environment obviously come with a JIT then? I think they should absolutely go for it, given the huge user base of python. Reasons like "but named functions can dynamically change" are not applicable, since JS has those same properties and can do it. They could start with optimizing the case where you call the sa…

> And why doesn't python's default runtime environment come with JIT? I think they should absolutely go for it, ensure the default python you get when you run python has a JIT, given the huge user base of python. 1. because CPython aims to be relatively simple and straightforward by choice 2. because the "huge user base" comes in large parts from the deep and extensive C API, which is absolute hell on a JIT 3. becaus…

> 1. because CPython aims to be relatively simple and straightforward by choice

It's a painful choice, and having to use numpy for everything that a loop normally could do but is too slow for, or discourage making functions because a function call is so slow, makes an otherwise elegant language less so

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

#52
post #2

An interpreter with a JIT is obviously faster than one without. Especially when dealing with CPU bound work. I'm not sure this is entirely noteworthy unless you somehow think CPython has a JIT. Would be much more interesting to compare to pypy.

pypy test.py 305.4699897766113 ms node test.js 111.49054491519928 ms python3 test.py 3576.0366916656494 ms Node still wins by a healthy margin.

Numba (asked by a commenter that haas since deleted:

638.8082504272461 ms

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

#54
post #34

Python feels noticeably slower than Node.js, particularly when running scripts with large amounts of imports. I now pretty much always use JavaScript for, well, scripting. Not sure why Python and Ruby are considered go-tos there.

I’ve been scripting in Python since 2003. Node wasn’t mature/viable at the time. Edit : didn’t exist at the time! Python is my go-to because I know the ecosystem well and can go from zero to done with minimal effort and research. Node has since (come into existence) and matured, and while it may be better/faster in some situations now, I haven’t encountered a project that has compelled me to switch. I suspect the ans…

Node.js was created in 2009, so it wasn't even born in 2003:

https://en.wikipedia.org/wiki/Node.js

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

#55
post #2

An interpreter with a JIT is obviously faster than one without. Especially when dealing with CPU bound work. I'm not sure this is entirely noteworthy unless you somehow think CPython has a JIT. Would be much more interesting to compare to pypy.

pypy test.py 305.4699897766113 ms node test.js 111.49054491519928 ms python3 test.py 3576.0366916656494 ms Node still wins by a healthy margin.

[deleted]

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

#56

I've seen these types of comparisons, and I understand there a loads of factors playing a part in them. However, it does make me wonder, why has python become to standard for data science? Is it Library support or purely community based?

For me, I have known Python since the 90s but only started using it as a daily driver a few years ago because there were big Microsoft and C/Java groups within my org and choosing one would alienate the other. So I used Python because it was good enough and non-threatening (and free and tons of libraries and healthy community, etc). I would have chosen javascript if there were as many packages. Also considered R, but hadn’t used it at the time.

I think Python is a good example of how being good enough is better than being awesome. And then it builds inertia through use and packages and friend of a friend recommendations.

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

#57
Ignoring the bad implementation of fib(n) and use of a Python interpreter without JIT... why does this matter?

Python and JavaScript are scripting languages. Their advantages are being highly portable and relatively easy to develop and maintain. Performance has always been a weakness of both languages when compared to their pre-compiled siblings. That limitation is often mitigated by "gluing" together functionality implemented in a more performance-oriented language, but even then nobody chooses a scripting language because they expect it to be faster than the competition.

Besides, this is hardly a fair comparison. Many tech giants have competed in the browser space for years by hyper-optimizing their JavaScript engines. Comparing the performance of Node/V8 to that of CPython is like me comparing my strength to that of a child.

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

#58

Earlier quoted context omitted.

pypy test.py 305.4699897766113 ms node test.js 111.49054491519928 ms python3 test.py 3576.0366916656494 ms Node still wins by a healthy margin.

Numba (asked by a commenter that haas since deleted: 638.8082504272461 ms

I asked, run it twice. The first time is for compilation. The second time it reaches 90ms on my machine.

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

#59

FYI: pypy3 is 10x faster than CPython on this benchmark. ~> python fib.py 4825.7598876953125 ms ~> pypy3 fib.py 514.7459506988525 ms

Also, add a couple of type annotations to the program: import time def fib(n: int) -> int: 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") The run: ~> mypyc fib.py And boom: ~> python >>> import fib 332.64994621276855 ms (FYI, mypyc is a compiler that's part of the mypy package).

there's a backslash in the print statement that crashes it

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

#60
post #34

Earlier quoted context omitted.

I’ve been scripting in Python since 2003. Node wasn’t mature/viable at the time. Edit : didn’t exist at the time! Python is my go-to because I know the ecosystem well and can go from zero to done with minimal effort and research. Node has since (come into existence) and matured, and while it may be better/faster in some situations now, I haven’t encountered a project that has compelled me to switch. I suspect the ans…

Node.js was created in 2009, so it wasn't even born in 2003: https://en.wikipedia.org/wiki/Node.js

Good catch. Brain fart on my part.
Post reply on HN