How Slow is JavaScript Really? JavaScript vs C++ (Data Structures & Optimization)

preview_player
Показать описание
Is JavaScript really that slow? Or is that just a leftover impression from the old days?

Follow me on:

In this video we talk a bit about JavaScript vs C++, and the performance difference between them. We'll talk quickly about the history of JavaScript before working through a few small benchmarks to compare performance between them, using various optimization levels for gcc. It's kind of interesting to see how much JavaScript's performance has evolved with JIT (just in time) compilation since the early Netscape days. The v8 team has made enormous strides in performance and is narrowing the gap with C++ year by year. We'll also walk through some examples of what you can do with your basic C++ code to squeeze more performance out, either by using better compiler flags or SSE/AVX intrinsics to get better usage out of your CPU.

What's covered:
* Super brief history of JavaScript and V8
* Benchmarks and comparison of JavaScript vs C++
* SSE and AVX intrinsics
* gcc -Ofast and float associativity
* Some closing thoughts on JavaScript's performance today, as well as C++.

Speed, Speed, Speed: JavaScript vs C++ vs WebAssembly:

Godbolt:

Wikipedia:

Various blog posts from V8 team:
Рекомендации по теме
Комментарии
Автор

i am maths and informatics teacher on private University in Poland, and it's rather distinctive that many students I teach are already programmer technicians / professionals with some market experience. I heard many times about superiority of C++ from people worried about performance when the lecture was about C#, JS or Python. Then those same people were completely missing the point on the lecture on algorithms and data structures. I notoriously see invalid solutions to rather simple problems - sometimes just tweaked to pass provided examples- and code that is completely unaware of data structures other than arrays, or maybe aware of linked lists, but using them like arrays. Dude, your C++ code will be slower than my JS code for not-small-enough data if you don't know what data structure or algorithm when to use

PaweMateuszBytner
Автор

Why would you use C? Assembly is much faster

redstone_mason
Автор

Most people complaining about your language of choice probably can't write half the logic you do

gugiserman
Автор

I think it'd be interesting to learn from you how to write efficient code in general (I understand you have worked with optimizing other people's code for games), and maybe a "learn efficient JavaScript together" series of videos.

dempa
Автор

I've heard you can beat most languages if you write your stuff directly in binary 🙃

Ferdam
Автор

episode 7: calling chemistry and electrical engineers to remodel all individual parts of all hardware pieces to be 100% oriented to the program we want

filipe_paixao
Автор

How you write the code is often more important than what language you write the code in. Understand what operations are efficient and which are not. Choose accordingly when performance matters.

CottidaeSEA
Автор

Great video! One thing I feel like you forgot to mention at the end is that, while yes, the V8 team is going to keep finding optimizations, so will the people working on GNU's GCC G++ compiler. It's essentially a race to see who can find clever optimizations faster.

cynical
Автор

Bet u can squeeze out even more performance with Holy C.

LewiLewi
Автор

Just checked out your instagram. Thought you were a 60-something year old man until now. Love your channel!

andrewsides
Автор

I think really nailed it with the "you get to understand your code" and that it "sucks to have a compilers job". The less constraints a language has, the more performance you can squeeze out. But the more constraints it has, the more transparent it gets. High level languages should never beat system level languages on performance, but it's nice to see the difference isn't too bad.

tuomaskoivistoinen
Автор

Your voice is so calm and watching your videos is just like a meditation

malcolmholmes
Автор

How about a benchmark of JavaScript vs C++ vs C++ via WebAssembly?

avi
Автор

I haven't really seen anyone do what you do in JS. Keep it up! As someone who's also working on a 2d mmorpg in javascript, I have already learned a ton of stuff from your videos

awweather
Автор

Nice hands on testing! Results were as ~ expected but concept and context is what matters. By having fun in JS you open up dependency-free, ready to launch learning experience to wider range of novice fellows.

Anything can be ported & fine-tuned for the final product :)

Rssks
Автор

Thank you for actually putting the results next to each other. So many YouTubers who do benchmarks expect you to scrub around to compare results.

o
Автор

The reality is that if an app runs slow -- it's likely that the code is the issue, not the language. Roughly speaking, in O(n) -- n's coefficient has much less impact than its power.
Yes, JS won't outperform c++, but it has more than enough fuel for a modern app (while surely gamedev being always greedy).
As they say, a released app is worth much more than a well-optimised asm file.
Good luck and happy coding!

kosnk
Автор

That comment in the beginning, comparing Java to Javascript... The guy who wrote that clearly has not programmed with any of those languages if he thinks they are similar xD

Atmos
Автор

What this tells me is "Know your tools!" so hard. Thank you.

j.c.h.
Автор

Im so glad I found this channel, Simon you make great videos.

jimpa