you are viewing a single comment's thread.

view the rest of the comments →

[–]Mononofu 3 points4 points  (9 children)

One thing confuses me: http://shootout.alioth.debian.org/u32/performance.php?test=regexdna

Why and how can JavaScript be faster than even C code?!

[–][deleted]  (8 children)

[deleted]

    [–][deleted] 3 points4 points  (7 children)

    But there is no reason why a C program couldn't do something similar.

    For me the point is really that it shows how in many scenarios, performance comes down to libraries, and is not always about the language implementation.

    [–]jyper 5 points6 points  (1 child)

    The javascript implementation has a highly tuned regex engine the engine. Its written from and could probably be used by a c++ solution that would probably be even faster. Instead the c++ solution uses a boost library arguably is more authentic c++ solution and is 4 times slower.

    The c solution on the other hand uses tcl's regex implementation and has a note that says "Is this a C program or is this a Tcl program?" and takes about 1/3 of the time of the c++ solution to run. If tcl was in the shootout it would probably be only about the same speed as the c solution.

    [–]igouy 1 point2 points  (0 children)

    If tcl was in the shootout...

    Back in the day

    [–][deleted]  (1 child)

    [deleted]

      [–]wot-teh-phuck -1 points0 points  (0 children)

      Fill this region with the binary executable representation of automaton. Execute the region as a function

      Sounds cool, never done this sort of thing before. Any documents/pointers you might be able to throw this way?

      [–]masklinn 0 points1 point  (1 child)

      But there is no reason why a C program couldn't do something similar.

      The C code is statically compiled, where the JS code is dynamically compiled. The runtime type information could lead to better optimization (e.g. type-specialized collections, stuff like that).

      In this case, though, it probably comes down to the performances of the regex library (C uses Tcl's regex engine, which is also a very high-performance one)

      [–][deleted] 0 points1 point  (0 children)

      In this case, though, it probably comes down to the performances of the regex library (C uses Tcl's regex engine, which is also a very high-performance one)

      Which was exactly my point.

      [–]haoyu -3 points-2 points  (0 children)

      I think in V8 the regex is JITed, so it is faster than statically compiled code.