While vs for

JavaScript performance comparison

Test case created by Tane

Preparation code

Benchmark.prototype.setup = function() {
    var keys   = ['foo', 'bar'];
    var values = [23, 42];
    var object = {};

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();
for (var i = 0, j = keys.length; i < j; i++) {
  var key = keys[i];
  object[key] = values[i];

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

Compare results of other browsers


Comment form temporarily disabled.

Add a comment