i wg897awgfw7gf

JavaScript performance comparison

Test case created and last updated

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var each1 = function(obj, fn) {
      var keys = Object.keys(obj), key;
      while (key = keys.shift()) {
        fn(key, obj[key]);
      };
    };
    var each2 = function(obj, fn) {
      var keys = Object.keys(obj);
      var length = keys.length;
      for (var i=0; i<length; i++) {
        var key = keys[i];
        fn(key, obj[key]);
      };
    };
   
    var obj = {};
   
    for (var i=0;i<10000;i++) {
    obj[i] = 'asdf';
    };
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
each1
each1(obj, function(key, val) {});
pending…
each2
each2(obj, function(key, val) {});
pending…

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

Compare results of other browsers

0 comments

Add a comment