A Closure Test

Benchmark created by Closure on


Setup

var len = 1000,
      a = function(key) {
        var arr = [5, 10, 15, 20, 25, 30];
        return arr[key];
      },
      b = (function() {
        var arr = [5, 10, 15, 20, 25, 30];
        return function(key) {
          return arr[key];
        };
      })();

Test runner

Ready to run.

Testing in
TestOps/sec
A
    for (var i = 0; i < len; i++) {
      a(Math.floor(Math.random() * 6));
    }
ready
B
    for (var i = 0; i < len; i++) {
      b(Math.floor(Math.random() * 6));
    }
ready

Revisions

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

  • Revision 1: published by Closure on