Why is C++ so much faster than Javascript, but harder to code?

This is nonsense. Most modern languages compile, even so-called interpreted languages like Python and Ruby. (they compile bytecode for their own stack-based VMs, but they compile nonetheless.) JavaScript compiles on most execution platforms. It has a JIT COMPILER, which is like any other binary compiler except that it works at runtime rather than beforehand.

In fact, JavaScript is faster than most interpreted languages because the JITs for it are quite good. Lua is often faster, however. Julia (a fairly new interpreted language) is basically always faster.

Java compiles to JVM bytecode at compile-time, but, like JavaScript, it is JIT compiled at runtime, but it is nonetheless generally faster. Go and Haskell are statically compiled to binary, but they are still sometimes slower than Java. Common Lisp is also compiled but rather slow.

Compiling to binary at runtime is not a make-or-break difference. Julia is faster than most statically compiled languages (Not C/C++ or Fortran, but most of the others, including Go and Java), but it compiles at runtime.

The reason C++ is faster is that it’s very natural to allocate memory for your data structures in advance, and C++ data structures can often be packed much more efficiently into contiguous blocks of data, which make it much easier for the processor to optimize for the cache. In JavaScript, because of the dynamic nature of the language, any variable name could point to any data type. This makes it much more difficult to allocate in advance, and much more difficult to pack data in arrays (it’s just a bunch of pointers to objects on the heap). Even when the JIT figures out how to optimize something, it needs a bunch of runtime type assertions to make sure it did the right thing, and it can fallback to slower code if it was wrong.

In short, C++ tries to force the programmer to organize data in a way that is efficient for the machine. JavaScript is focused on making data organization easy for the programmer and can’t give the machine any guarantees about what it will need before the code runs. (The reason Julia is so fast, even though it’s interpreted is that it can give the machine more guarantees about memory allocation. This is also true of Java, which is JIT compiled at runtime.)

COMMENTS

Name

5G,1,Business,2,Bussiness,3,C,2,C++,4,CodeProject,3,Companies,5,Computer,1,Dev.to,1,Facebook,1,Featured,1,Future,2,Google,4,Javascript,2,Microsoft,2,Motivation,6,PHP,3,Programmer,6,Programming,14,Projects,1,Python,3,Quantum,1,Quora,10,Software Development,3,Tech,4,VS Code,2,
ltr
item
9to5Programmer: Why is C++ so much faster than Javascript, but harder to code?
Why is C++ so much faster than Javascript, but harder to code?
This is nonsense. Most modern languages compile, even so-called interpreted languages like Python and Ruby. (they compile bytecode for their own stack-based VMs, but they compile nonetheless.) JavaScript compiles on most execution platforms. It has a JIT COMPILER, which is like any other binary compiler except that it works at runtime rather than beforehand.
https://i.imgur.com/TcTJs8a.jpg
9to5Programmer
http://www.9to5programmer.com/2019/02/why-is-c-so-much-faster-than-javascript.html
http://www.9to5programmer.com/
http://www.9to5programmer.com/
http://www.9to5programmer.com/2019/02/why-is-c-so-much-faster-than-javascript.html
true
1435496506228626257
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy