native vs typed js array speed

JavaScript performance comparison

Revision 74 of this test case created by

Preparation code

<script>
  var arraySize = 10000;
  
  var typedBuffer = new ArrayBuffer(4 * arraySize);
  var typedArray = new Uint32Array(typedBuffer);
  var nativeArray = [];
  var nativeArray2 = [];
  var nativeArray3 = new Array(arraySize);
  var nativeArray4 = new Array(arraySize);
  var obj = Object.create(null);
</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
Native array Write (discrete with new Array(arraylength))
//Read
for (var i = 0; i < arraySize; i++) {
 var value = !!nativeArray3[i];
}
pending…
Native array Write (discrete then fill 0, new Array(...))
//Write
for (var i = 0; i < arraySize; i += 2) {
 nativeArray4[i] = true;
}

for (var i = 0; i < arraySize; ++i) {
 nativeArray4[i] = nativeArray4[i] || false;
}
pending…
Native array Read (continuous, filled 0 in empty cell, new Array(...))
//Read
for (var i = 0; i < arraySize; i++) {
 var value = !!nativeArray4[i];
}
pending…
Native Object Write
//Write
for (var i = 0; i < arraySize; i += 2) {
 obj[i] = true;
}
pending…
Native Object Read
//Read
for (var i = 0; i < arraySize; i++) {
 var value = !!obj[i];
}
pending…
Native array Write (discrete)
//Write
for (var i = 0; i < arraySize; i += 2) {
 nativeArray[i] = true;
}
pending…
Typed array Write (discrete)
//Write
for (var i = 0; i < arraySize; i += 2) {
 typedArray[i] = true;
}
pending…
Native array Read (continuous)
//Read
for (var i = 0; i < arraySize; i++) {
 var value = !!nativeArray[i];
}
pending…
Typed array Read (continuous)
//Read
for (var i = 0; i < arraySize; i++) {
 var value = !!typedArray[i];
}
pending…
Native array Write (discrete then fill 0)
//Write
for (var i = 0; i < arraySize; i += 2) {
 nativeArray2[i] = true;
}

for (var i = 0; i < arraySize; ++i) {
 nativeArray2[i] = nativeArray2[i] || false;
}
pending…
Native array Read (continuous, filled 0 in empty cell)
//Read
for (var i = 0; i < arraySize; i++) {
 var value = !!nativeArray2[i];
}
pending…
Native array Write (discrete with new Array(arraylength))
//Write
for (var i = 0; i < arraySize; i += 2) {
 nativeArray3[i] = true;
}
pending…

Compare results of other browsers

Revisions

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

0 Comments