Live data from Hacker News

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

jott.live

101–110 of 119 posts

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

#101

Earlier quoted context omitted.

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

> Python lets you do _far_ more shenanigans that Javascript does Does JavaScript let you do this monstrosity of terrible code? Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> class Dog(object): ... def speak(self): ... print("bark!") ... >>> class Cat(object): ... def speak(self): ... print("me…

You can replace an object's prototype in JS, wouldn't that do the same?

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

#102

Earlier quoted context omitted.

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

> Python lets you do _far_ more shenanigans that Javascript does Does JavaScript let you do this monstrosity of terrible code? Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> class Dog(object): ... def speak(self): ... print("bark!") ... >>> class Cat(object): ... def speak(self): ... print("me…

Yes, you absolutely can. In fact, this was part of my ES5 Date constructor polyfill.

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

#103
post #26

This is a pretty terrible implementation of fib(n).

Regardless node IS definitively one of the fastest interpreted platforms around. It is well known that it is faster than python. Python wins in other areas, including being a much much better designed language.

Probably comes from V8 (JS engine in node), likely being the most heavily optimized language runtime engine ever made.

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

#104
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

Node.js not existing probably contributed significantly to its non-viability in 2003. ;-)

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

#105

Earlier quoted context omitted.

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

To be fair, python itself isn't jitting anything, while node is.

Numba doesn't really qualify as JIT if what it's really doing is compiling it and caching the results to disk then reading from them in the future for faster execution... that's just a compiler.

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

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

Let me help you detox that:

> An interpreter with a JIT is faster than one without. Especially when dealing with CPU bound work. Would be interesting to compare to pypy.

Sure, here is pypy:

  > pypy3 main.py
  282 ms

  > node main.js
  105 ms
Without JIT:

  > python3 main.py
  2818 ms

  > node --jitless main.js
  998 ms
For fun:

  > cargo run --release -q
  20 ms
I enjoy brrrrrm's post for its brevity and the acknowledgement of common folk tools.

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

#108
post #16

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.

The numbers are small so there shouldn’t be any difference for fib(35)

They're fundamentally stored as and operated on in different ways. A BigInt does suddenly become a BigInt when in excess of MAX_SAFE_INTEGER, it's a BigInt even with a value of 1n.

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

#109
post #107
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.

Let me help you detox that: > An interpreter with a JIT is faster than one without. Especially when dealing with CPU bound work. Would be interesting to compare to pypy. Sure, here is pypy: > pypy3 main.py 282 ms > node main.js 105 ms Without JIT: > python3 main.py 2818 ms > node --jitless main.js 998 ms For fun: > cargo run --release -q 20 ms I enjoy brrrrrm's post for its brevity and the acknowledgement of common f…

Tried it in PHP v8 (on Windows):

.\php fib.php 1402.1289348602 ms

and with PHP8's new JIT opcache on:

.\php -dopcache.enable_cli=1 -dopcache.jit_buffer_size=200M fib.php 219.55609321594 ms

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

#110

Earlier quoted context omitted.

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

> Python lets you do _far_ more shenanigans that Javascript does Does JavaScript let you do this monstrosity of terrible code? Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> class Dog(object): ... def speak(self): ... print("bark!") ... >>> class Cat(object): ... def speak(self): ... print("me…

A lot of people have responded "yes", but no one's taught you how yet, so here's some example code that you can paste into your browser's Devtools or Node's REPL:

    class Dog {
      speak() {
        console.log("bark!");
      }
    }
    class Cat {
      speak() {
        console.log("meow!");
      }
    }
    animal = new Dog();
    animal.speak();
    Object.setPrototypeOf(animal, Cat.prototype);
    animal.speak();
This will produce:

    bark!
    meow!
Post reply on HN