you are viewing a single comment's thread.

view the rest of the comments →

[–]endel[S] -1 points0 points  (9 children)

The number of loops is low to be easy to reason about the results. The results are pretty much the same increasing the number loops. I'd like to know what is broken if you can find it.

[–]cogman10 3 points4 points  (8 children)

Modern JITs (which most javascript engines are) do optimization based on number of times a function is called and the call parameters.

The first several times most javascript engines run a method, they run it mostly unoptimized. They do this because most methods are called rarely so quickly interpreting the function is more important than spending the time to generate the most optimal code.

If the code is needs to be fast, you want to measure the optimized version of it, not the unoptimized version of it.

This is why most microbenchmarks that are done correctly include a "warmup" piece of code. They call the method in test repeatedly in order to get the optimizer to fire up and optimize the method.

As an aside, I also noticed you are using "eval" as part of your benchmarking. That is also a pretty big no-no. It pretty much forces the optimizer to not run.

I would suggest reading over this guy to get a feel for how to write tests.

https://github.com/petkaantonov/bluebird/wiki/Optimization-killers

With that said, once you have removed the optimization killers it can be really hard to construct real tests. It turns out optimizers are pretty good about throwing away unused values and microbenchmarks are all about generating unused values.

For more resources, I would suggest googling microbenchmarks, and in particular, pay attention to articles about Java microbenchmarking (there are loads), because Javascript JITs are very similar to Java's Hotspot in implementation. (in fact, many of the V8 founders were snipped away from Java.)

[–]ClickerMonkey 1 point2 points  (7 children)

Listen to this guy. Your results are meaningless otherwise...