All modern browsers optimize code in 3 stages:


  • The JavaScript source-code is first parsed, tokenized and compiled to byte-codes. A process virtually identical to C# or Java
  • The resulting bytecode segments are further grouped into JIT capable or interpreter only segments
  • JIT capable segments are converted to native machine-code for optimal speed


If a piece of JavaScript cannot be JIT compiled, it remains bytecode and is executed in interpreted mode, meaning that the browser will read one bytecode instruction, act on it, read the next - and so on. Since the code is already converted into bytecodes in memory, this is not as slow as you might think, but obviously not even close to actual machine code that JIT compilation produces. So indeed, the way that your write your code actually matters.


To give you some indication of the performance to can expect:


  • Interpreted bytecode is ca 80% slower that a native C program.
  • JIT compiled code is ca 60% slower that a native C program
  • Asm.js is 40% slower (*) that a native C program.
  • WebAssembly is 10% slower that a native C program.


(*) Asm.js is remarkably flat when it comes to performance. What must be understood is that Asm.js still counts as ordinary JavaScript, it performs so well because it avoids accessing the DOM completely (typically used by games and demos). Since the nature of a JSVM (JavaScript virtual machine) is asynchronous, event driven execution - 100% cpu core utilization is impossible with Asm.js. For that, you need WebAssembly.


I must underline, that the performance indicators listed above must not be interpreted as something chiseled in stone. Your computer hardware, the operating system, background tasks, scheduler, threading, memory and browser versions all affect the performance a given technique can deliver. The numbers above are the result of testing various techniques on many different computers, both x86, ARM and PPC; Microsoft Windows, Linux and Mac OS. So read the factors purely as guiding indicators, not hard facts.