JavaScript is probably like 10x or 100x slower than C or similar languages when you write something bigger and any of the following happens:
- the ratio of code size to run time is too big. Then the jit can’t keep up.
- you use a lot of value types. Them be structs in C, no need for allocation. In JS them be objects. The JS VM will try to escape analyze them, and it will succeed some of the time, but fail enough of the time to cause massive punishment.
- you churn objects while having a large base heap size and the generational hypothesis holds only a bit. Then you’ll wait for the GC a lot.
- you have a class hierarchy with many descendants and you often access properties or call methods on the base type. Then vtables or whatever work great but JS inline caches blow up.
- probably lots of other conditions.
Write enough code and at least one of these will hold and you’ll be slow in JS, fast in C.
(Source: I work on JSC and I implemented a lot of its optimizations. Benchmarks like the ones in this post are the sort of thing my JITs eat for breakfast. It’s cool to see people throwing me softballs but I like to be honest about what the technology I work on is capable of.)