Live data from Hacker News

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

jott.live

71–80 of 119 posts

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

#71
post #43
post #15

Who would've thought that V8 that gets millions invested in it by a huge company would outperform community made Python.

I'd be hard pressed to find any mainstream language that underperforms naïve CPython. Community driven or not.

Bash is pretty damn slow.

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

#72
post #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 i…

I think it's notable that the gap between dominant scripting languages for simple function-call bound code has become quite large.

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

#73

Doesn't the Node.js version use double precision floating point vs python using infinite precision integers ? That would explain part of the difference in performance, and make the python version exact, but js version inexact.

This looks like most of the difference.

  JS with number              138 ms   (x1)
  JS with BigInt (eg. 35n)   2620 ms   (x19)
  Python                     3260 ms   (x24)

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

#74
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.

> 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…

Armin Ronacher, author Flask, actually has a good talk about this. The gist of it the way Python's internals leak into the language makes it very difficult to build a performant JIT that wouldn't break a large amount of userspace code.

Python lets you do _far_ more shenanigans that Javascript does; and a lot of large libraries depend on some of that behavior. Breaking it would probably cause a new 2 -> 3 situation.

https://www.youtube.com/watch?v=qCGofLIzX6g&feature=emb_titl...

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

#75

Earlier quoted context omitted.

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.

Second run was 200ms for me, still 2x node.

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

#76

Earlier quoted context omitted.

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.

I would expect numba to win, but I also do not think it is a fair comparison.

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

#77
post #42

Earlier quoted context omitted.

Seems like an unduly harsh take. Is everyone just supposed to inherently know this fact about cpython or find it unsurprising when they run across it? "Obviously this isn't the most comprehensive benchmark, but the results are surprising to me." I fully agree with this and I learned something new about cpython's weakpoints today!

If I’m writing an article about benchmarking, then yes.

In the author's defence, the "article" isn't even 50 words long.

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

#78
Compare languages on performance is weird. Every language is made with another philosophy.

Python isnt made for performance, but for good code readability. Write clear, logical code for small and large-scale projects. It is also made by Guido to build applications in less time. Guido knows his language isnt the fastest, but thas wasnt the goal with Python.

Node.js is also made for other applications than Python. It's great for web developers to be in the "JavaScript everywhere" world. So it is easy for web developers to write backend and frontend code with the "same" language. It's also great for event's and "real time" communication with the (web) application.

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

#79

1. Python doesn't have a JIT. This shouldn't be surprising or headline worthy. 2. Why benchmark an O(2^n) fibonacci? It's basically benchmarking call frame creation. 3. A single order of magnitude is honestly not that impressive a speedup for JIT vs. no JIT. Might have a lot to do with the inefficiency of the recursive fibonacci func. Also, to quote another poster: @numba.njit def fib(n): if n == 1 or n == 0: return…

> Which is...effectively identical to Node?

You'd have to also run the node version on your machine to know, as it's unlikely you have the exact same setup as TFA.

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

#80

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?

It's because to a reasonably approximation of "None" - none of the actual data science runs in Python, it's all hyper customized libraries which do run (close to) metal fast once the data has been loaded into the appropriate data structures. Pandas is a shim on top of Numpy, which heavily leverages the Fortran77 BLAS/LAPACK libraries. Python is used at the top of the stack because it's an easy language to learn, you…

> Python is used at the top of the stack because it's an easy language to learn, you can get started fast, and, for places where performance is important - nothing is running in Python anyways.

Also interactivity and quick feedback cycle, stuff like Jupyter Notebooks (né IPython Notebooks, a spinoff from the IPython project), matplotlib, ...

Post reply on HN