Reference indexed object in loop or variable with array values too

JavaScript performance comparison

Test case created by Rich

Preparation code

<script>
  function GenericObject(mType, mKey) {
   this.id = 1;
   this.type = mType;
   this.typedArray = mType + "=" + mType + "="
   mKey + "=" + this.id;
   this.keyId = mKey;
  }
  
  var array = new Array();
  for (var i = 0; i < 1000; i++) {
   if (i % 2 == 0) {
    array[i] = new GenericObject('a', i);
   } else {
    array[i] = new GenericObject('b', i);
   }
  }
  
  var array1a = new Array();
  var array1b = new Array();
  var array1c = new Array();
  var array1d = new Array();
</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
Reference the object throughout with split array.
for (var array_x = 0, arraylen = array.length; array_x < arraylen; array_x++) {
 var thisAr = array[array_x].typedArray.split('=');
 array1c.push(thisAr[0], thisAr[1], thisAr[2], thisAr[3]);
}
pending…
Reference variables of the object for split array.
for (var array_x = 0, arraylen = array.length; array_x < arraylen; array_x++) {
 var thisAr = array[array_x].typedArray.split('=');
 array1d.push(array[array_x].typedArray.split('=')[0], array[array_x].typedArray.split('=')[1], array[array_x].typedArray.split('=')[2], array[array_x].typedArray.split('=')[3]);
}
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