javascriptc++v8google-nativeclient

V8 vs NativeClient


I know that V8 compiles JavaScript to native machine code (IA-32, x86-64, ARM, or MIPS CPUs) before executing it. And I have read that google native client compiles C/C++ to machine code, so if those two technologies return same result(machine code), What's the difference between them except for the used languages(JavaScript C/C++)?


Solution

  • Well, given a CPU architecture (say, you run on an Intel box) you can say that any technology ends up compiling to machine code, right? So Python, Perl, Javascript, C++, Fortran and so on are just different languages that get compiled down to machine code (Python and Perl are usually bytecode VMs but these also run as machine code down in the bottom).

    v8 is a Javascript runtime. Yes, it uses compilation under the hood to speed up your code. Other JS runtimes do that too (*monkey of Firefox, etc.)

    NaCl (through PNaCl or not) lets you write C/C++ code that ends up executing in the browser. This has some advantages and disadvantages vs. JS, and which ever you pick depends on your specific needs. For most applications JS is more suitable because it's a higher-level language so it's more convenient to program in. Some applications, however, need special levels of performance that's not achievable with JS (at least at this time). These applications benefit from having a NaCl module inside, that usually takes part in a larger architecture which includes JS as well.

    Read this for more details.