3 ms·
Microbenchmarks I know, but it looks like a magnitude slower than C++ to me: https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/node-gpp.html
by hu3 5y ago
Microbenchmarks I know, but it looks like a magnitude slower than C++ to me:
https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/node-gpp.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
- nicoburns 5y agoI see a factor of 2 in the closest benchmarks. A factor of 4-5 for the middlish ones, and a factor of 10 for the least close. But it's worth noting that a lot of the those C++ examples are making heavy use of SIMD.
- netr0ute 5y agoCan you do SIMD with JS? If not, then C++ has the real advantage.
- pineconewarrior 5y agoSIMD.js was abandoned in browsers but you can use SIMD in WASM.
- mhh__ 5y agoI was about to write that I'd be disappointed if V8 didn't vectorize simple loops, but I googled it and apparently it doesn't so maybe I should be disappointed.
- ygra 5y agoIs there any JIT that does auto-vectorization? I kinda got the feeling from C/C++ compilers that auto-vectorization is brittle and unpredictable even there and that's with all the time an AoT compiler can invest into optimization. A JIT always has to tread the line (or multiple lines in case of tiered compilation) between optimization effort and benefit. And the usual trade-off between larger and smaller code. So speculatively unrolling short loops just to see whether anything could be vectorized is perhaps out of scope for most JITs and even in AoT-compiled languages the preferred way of getting the most out of vector instructions is just to explicitly vectorize hot loops as a programmer, as the result is often better than what the compiler could do.
- kaba0 5y agoYeah the JVM does autovectorization, but this feature is very finicky (everywhere, not only in JIT context). That’s why in Java now you have the Vector API, which allows one to create very low-level, but reliably vectorizable code (with the added benefit of sane fallback to for loops on non-supported CPUs)
- fenomas 5y agoThose benchmarks run the program once from a cold start, right? When people talk about JS nearing c++ performance I think they generally mean cases like the steady-state performance of a game loop, after the JS engine has had a chance to observe the hot code for a little while.
- igouy 5y agoAnd some of those runtimes are 45 cpu secs. If that’s not enough chance to observe the hot code…