While vs for

JavaScript performance comparison

Test case created by Tane

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var keys   = ['foo', 'bar'];
    var values = [23, 42];
    var object = {};
};
</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
while loop
while (keys.length) {
  var key = keys.pop();
  object[key] = values.pop();
}
pending…
for
for (var i = 0, j = keys.length; i < j; i++) {
  var key = keys[i];
  object[key] = values[i];
}
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