Eval+Join vs Reduce

Benchmark created by Joshua T Kalis on


Description

I know eval is evil but how does it perform next to reduce in this particular instance?

Setup

var sm = [10, 23, 41, 13],
        md = [1, 7, 13, 22, 36, 42, 55, 60, 72, 88, 90, 103, 123, 158, 200, 222, 323, 443, 501, 545, 610, 728, 880, 891, 903, 919, 1001, 2011]
        lg = (function() {
          var result = [];
          for (var i = 0; i < 200; i++) {
            result.push(~~ (Math.random() * 1000));
          }
          return result;
        }());

Test runner

Ready to run.

Testing in
TestOps/sec
eval+join
eval(sm.join("+"));
eval(md.join("+"));
eval(lg.join("+"));
ready
reduce
sm.reduce(function (a, b) { return a + b; });
md.reduce(function (a, b) { return a + b; });
lg.reduce(function (a, b) { return a + b; });
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by Joshua T Kalis on