faster-than-c icon indicating copy to clipboard operation
faster-than-c copied to clipboard

a jsPerf benchmark of your eval example

Open Myaushka opened this issue 11 years ago • 9 comments

I thought it would be interesting to actually test your eval claim. So, I created a jsPerf test (based on the Benchmark.js library, which happens to be named the same as one of the files in your repo):

http://jsperf.com/mesdfleifi

It's way more impressive than I expected! Check out the graph at the end!

It could be an interesting addition to your article.

Myaushka avatar Feb 07 '14 07:02 Myaushka

I thought it might be about http://en.wikipedia.org/wiki/Loop_unwinding, but then I found this: http://jsperf.com/unrolled-loops

It's not exactly the same thing, so maybe "further research is needed."

Myaushka avatar Feb 07 '14 07:02 Myaushka

Thanks for putting this together, the numbers are impressive indeed. I'm not maintaing this repo, I just put it together once for a talk, but if you want to make changes I'd be happy to merge them in.

Anyway, I'm not sure what the technique should be called. Yes, it's loop unwinding, but it's neither done by the compiler, nor the programmer. I almost want to call it a userland JIT, but since it's not compiling to a lower level representation that seems inappropriate. I guess "runtime code generation for loop unwinding" is the best way to describe it.

felixge avatar Feb 07 '14 07:02 felixge

Actually, I updated the test to be more fair, and it's a lot more reasonable. I originally didn't include the loop unwinding code in the test, but it should be included, unless it's reused (is it?)

Myaushka avatar Feb 07 '14 07:02 Myaushka

It's still faster, though, although not astronomically so.

Myaushka avatar Feb 07 '14 07:02 Myaushka

So the details on how the benchmark runs become very important. This technique will yield very high results when parsing a huge number of rows from the same table. It's not so useful when doing lots of queries with smaller result sets where the parser needs to be re-generated every time (which is what I suspect ends up happening with your change to the setup).

felixge avatar Feb 07 '14 07:02 felixge

Yes, exactly. I think I'll add a 3rd case and rename the cases appropriately!

Myaushka avatar Feb 07 '14 07:02 Myaushka

Cool! Thanks for making these standalone test cases!

felixge avatar Feb 07 '14 07:02 felixge

This exactly proves your point about specific techniques being applicable to specific problems!

Myaushka avatar Feb 07 '14 07:02 Myaushka

Anyway, I'm not sure what the technique should be called. Yes, it's loop unwinding, but it's neither done by the compiler, nor the programmer. I almost want to call it a userland JIT, but since it's not compiling to a lower level representation that seems inappropriate. I guess "runtime code generation for loop unwinding" is the best way to describe it.

Loop unwinding might be new to javascript language but is quite popular in other c-family languages from much, much-older times. But I must say, impressive work :+1:

agauniyal avatar Jan 31 '16 13:01 agauniyal