eval accessor

JavaScript performance comparison

Test case created by Caleb James DeLisle

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  window.obj = {};
  for (var i = 0; i < 100; i++) { obj['x'+i] = i; }

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
eval
for (var n in obj) {
    if (!n.indexOf('get_')) { continue; }
    obj['get_' + n] = new Function('return obj["' + n + '"]');
}

for (var i = 0; i < 100000; i++) {
    obj['get_x' + (i % 100)]();
}
pending…
function template
for (var n in obj) {
    if (!n.indexOf('get_')) { continue; }
    (function (n) {
        obj['get_' + n] = function () { return obj[n]; };
    }(n));
}

for (var i = 0; i < 100000; i++) {
    obj['get_x' + (i % 100)]();
}
pending…

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

0 Comments