6

According to language benchmarks, JavaScript V8 is faster than other programming languages at regex-dna program. So, why node.js applications (i.e. http server) isn't faster than C applications (i.e. Nginx, Lighttpd)?

Jeff
  • 14,365
  • 8
  • 30
  • 30
  • 1
    Why is apache faster than lighttpd, they are both programmed in C? – AndreKR Nov 18 '10 at 22:38
  • Now _that_ is a different question @AndreKR – jcolebrand Nov 18 '10 at 22:39
  • You do know that C is also compiled to machine code, don't you? – Jonas Elfström Nov 18 '10 at 22:40
  • The Javascript V8 engine itself is written in C++ (not that that would necessarily matter) – Sagar Nov 18 '10 at 22:42
  • 10
    According to the figures a Ferrari is faster than many other vehicles at going round a racetrack, so why doesn't it go faster than a tractor when pulling a plough? – NickFitz Nov 18 '10 at 22:49
  • @NickFitz awesome analogy, although it would be sad to run a Ferrari through fields :( – Sagar Nov 18 '10 at 23:15
  • @Sagar: I saw more or less exactly that when I was in Ireland over the summer. Still not sure where the farmer got the Ferrari, though. – Stephen Canon Nov 18 '10 at 23:19
  • @NickFitz: So, using regex in C is racing with tractor and building an HTTP server in Node.js is pulling a plough with a Ferrari? – Jeff Nov 18 '10 at 23:29
  • 1
    @PolatAlemdar ~ Please understand that the V8 and other runtimes for interpreted languages are often optimized for using Regexes because that is one of the primary use cases of those languages. The primary use-case of a webserver is NOT to process Regexes. So while the V8 engine may be optimized for Regex, that has no bearing on it's ability to handle IO sockets or IO file requests. – jcolebrand Nov 18 '10 at 23:37

5 Answers5

34

Because V8 applications are javascript applications. Even if the javascript is finally compiled to machine code the runtime characteristics are different.

For example if you call a function in an object and that object does not define the function the runtime must locate the function by traversing the prototype hierarchy, this hierarchy can change at any time during the lifetime of a program. There are clever optimizations that can be done but the overhead exists nevertheless.

There is also the memory model. Javascript is garbage collected and GC takes cpu cycles.

fedesilva
  • 1,532
  • 13
  • 12
11

Because serving http requests is a different problem than regex-dna.

The fact that A is faster than B at one task doesn't say anything about what to expect from some other task.

Obligatory bad car analogy: A ham sandwich is much tastier than a porsche. Why isn't it faster from 0-60?

Stephen Canon
  • 103,815
  • 19
  • 183
  • 269
  • Parsing HTTP requests and regex mustn't be irrelevant as in your semantic example. Anyways, Would you drive a sandwich or eat a porsche to code an HTTP server? – Jeff Nov 18 '10 at 23:25
  • @PolatAlemdar ~ There is a language barrier here. Those are idioms in English. – jcolebrand Nov 18 '10 at 23:35
  • -1 for the bad car analogy, the benchmarks game website Polat Alemdar points to itself shows another half-dozen different tasks, and http://shootout.alioth.debian.org/flawed-benchmarks.php#thinking – igouy Nov 19 '10 at 17:20
3

For one C is essentially the benchmark language for computation speed. The compliers these days are very good and produce very efficient machine code. What this means is that the upper limit for performance is what you can get with C.

In one of his presentations about node.js Ryan Dahl (the creator) said that node is about as fast as C. (but GC and other things do have an impact on performance, not to mention that V8 needs time to properly optimize things)

xj9
  • 3,381
  • 2
  • 24
  • 23
0

In the that benchmark there are 15 different programs and only one dna-regex benchmark where you can see JavaScript V8 is faster. On other benchmarks JavaScript is much lower in performance. You can choose program in the first select, look at this one.

user13500
  • 3,817
  • 2
  • 26
  • 33
-5

According to language benchmarks, JavaScript V8 is not faster than GCC at binary-trees program.

According to language benchmarks, JavaScript V8 is not faster than GCC at k-nucleotide program.

According to language benchmarks, JavaScript V8 is not faster than GCC at n-body program.

According to language benchmarks, JavaScript V8 is not faster than GCC at spectral-norm program.

According to language benchmarks, JavaScript V8 is not faster than GCC at fasta program.

According to language benchmarks, JavaScript V8 is not faster than GCC at reverse-complement program.

According to language benchmarks, JavaScript V8 is not faster than GCC at pidigits program.

igouy
  • 2,547
  • 17
  • 16
  • @Polat Alemdar - You asked "So, why node.js applications (i.e. http server) isn't faster than C applications" and the answer is that you have no reason to think they should be faster than C applications. You took one measurement out of context and ignored the other 7. – igouy Nov 23 '10 at 01:46