
V8 performance can beat C sometimes - pmelendez
http://benchmarksgame.alioth.debian.org/u64/benchmark.php?test=regexdna&lang=all&data=u64
======
lambda
This isn't V8 beating C; this is one regex library being faster than another
(both written in C or C++).

~~~
rayiner
No, V8's regex library is not written in C. V8 compiles its regular
expressions to machine code at runtime. The availability of the compiler at
runtime can be a liability for things like startup time or memory use, but can
also be a key advantage in situations like regular expression parsing or
packet processing.

~~~
debacle
Well it's not written in JavaScript, so as the OP said it's either C or C++.

~~~
rayiner
The code that's doing the actual matching is not written in C or C++. It's an
internal regex bytecode compiled directly to machine code.

------
NathanKP
The code for the C implementation is incredibly verbose compared to the code
for the JS implementation.

JS:
[http://benchmarksgame.alioth.debian.org/u64/program.php?test...](http://benchmarksgame.alioth.debian.org/u64/program.php?test=regexdna&lang=v8&id=2)

C:
[http://benchmarksgame.alioth.debian.org/u64/program.php?test...](http://benchmarksgame.alioth.debian.org/u64/program.php?test=regexdna&lang=gcc&id=1)

~~~
unwind
That's just ... absurd, in comparison at least. It uses TCL _and_ glib?!

I'll go out on a limb here and claim that this C program is not the shortest
possible equivalent to the JS version.

~~~
igouy
That isn't the only C program shown :-)

[http://benchmarksgame.alioth.debian.org/u64/program.php?test...](http://benchmarksgame.alioth.debian.org/u64/program.php?test=regexdna&lang=gcc&id=4)

[http://benchmarksgame.alioth.debian.org/u64/program.php?test...](http://benchmarksgame.alioth.debian.org/u64/program.php?test=regexdna&lang=gcc&id=2)

------
detrino
No this is not V8 performance beating C.

This is V8 calling a regexp library written in C++. C just happens to be using
a different library that is slower.

~~~
pmelendez
>"This is V8 calling a regexp library written in C++"

But it also beat the C++ implementation though.

~~~
detrino
I guess that re2 (the library that this C++ code is using) is slower than
irregexp (the library that V8 is uses) on this benchmark.

------
varelse
Rather than argue back and forth about which regex implementation is better
here, I'd simply note the absence of multicore numbers for V8 and that the
crappy Tcl library beats single-threaded Javascript when run multicore.

It would be interesting, however, to compare the performance here to that of
the "grep" command on the same expressions. I'd be surprised at anything short
of a total smackdown of Javascript V8.

I would expect an even bigger smackdown if one invoked GPUs:

[http://bkase.github.io/CUDA-
grep/finalreport.html](http://bkase.github.io/CUDA-grep/finalreport.html)

Even more interesting would be an OpenCL implementation that did exactly what
V8 is doing to the regexes (Why? Because it can).

And total aside, this is why I don't participate in TopCoder competitions -
they never let you have any real fun.

~~~
_random_
The idea was obviously to pick a test and environment that would make it look
like V8 can beat something other than interpreted JS. Otherwise it would've
been the complete package: string manipulation, numerical computation, multi-
core etc.

------
majke
If I read this benchmark right: v8 regexps are faster than TCL regexps.

Hardly surprising.

~~~
pmelendez
I also beats all the other regexps engines though.

~~~
kevingadd
Likely because V8 only works on platforms where JIT is possible, so the regex
engine relies on JITting specialized native code for the regex. A portable
C/C++ regex library can't really do that.

------
jwineinger
The V8 version used nearly 50% more memory than the C version. It is well
known that you can often get faster execution times at the cost of increased
memory usage.

~~~
igouy
More like 30%

------
danso
Anyone else read this as "VB" as in, "Visual Basic"? Now _that_ I would
bookmark :)

~~~
vezzy-fnord
Yes, I got the same impression.

------
anjanb
why is golang so much slower compared to Java ? Is it because the language is
immature or because the language libraries are immature ?

~~~
chimeracoder
Go not only uses a different library for processing regular expressions, but a
different algorithm altogether. It is slower in some cases than the standard
PCRE implementations but faster in others.

[http://code.google.com/p/re2/](http://code.google.com/p/re2/)

~~~
igouy
Go program using PCRE

[http://benchmarksgame.alioth.debian.org/u64/program.php?test...](http://benchmarksgame.alioth.debian.org/u64/program.php?test=regexdna&lang=go&id=8)

------
jonnii
Quickly, everyone convert their C to javascript!

------
jbverschoor
So ruby java lua and python are all about the same?

------
jonrx
Congralutations! :-)

(And the program is IMHO clearer than the C implementation)

~~~
pmelendez
To the V8 team and the implementer of the testing program.

Disclaimer: I had anything to do with this, I just thought it was interesting
enough to post it.

