typed arrays

JavaScript performance comparison

Revision 2 of this test case created by Dmitry Podgorniy

Info

Test the performance of typed arrays vs normal arrays

Preparation code

<script>
  var N = 100000;
  var arr = new Array(N),
      i8arr = new Int8Array(N),
      ui8arr = new Uint8Array(N),
      i16arr = new Int16Array(N),
      ui16arr = new Uint16Array(N),
      i32arr = new Int32Array(N),
      ui32arr = new Uint32Array(N),
      f32arr = new Float32Array(N),
      f64arr = new Float64Array(N);
 
  var i;
  for (i = 0; i < N; i++) {
   arr[i] = i;
   i8arr[i] = i;
   ui8arr[i] = i;
   i16arr[i] = i;
   ui16arr[i] = i;
   i32arr[i] = i;
   ui32arr[i] = i;
   f32arr[i] = i;
   f64arr[i] = i;
  }
</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
Array
var i;
for (i = 0; i < N; i++) {
 arr[i] = arr[i] * arr[i];
}
pending…
i8arr
var i;
for (i = 0; i < N; i++) {
 i8arr[i] = i8arr[i] * i8arr[i];
}
pending…
ui8arr
var i;
for (i = 0; i < N; i++) {
 ui8arr[i] = ui8arr[i] * ui8arr[i];
}
pending…
i16arr
var i;
for (i = 0; i < N; i++) {
 i16arr[i] = i16arr[i] * i16arr[i];
}
pending…
ui16arr
var i;
for (i = 0; i < N; i++) {
 ui16arr[i] = ui16arr[i] * ui16arr[i];
}
pending…
i32arr
var i;
for (i = 0; i < N; i++) {
 i32arr[i] = i32arr[i] * i32arr[i];
}
pending…
ui32arr
var i;
for (i = 0; i < N; i++) {
 ui32arr[i] = ui32arr[i] * ui32arr[i];
}
pending…
f32arr
var i;
for (i = 0; i < N; i++) {
 f32arr[i] = f32arr[i] * f32arr[i];
}
pending…
f64arr
var i;
for (i = 0; i < N; i++) {
 f64arr[i] = f64arr[i] * f64arr[i];
}
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. Here’s a list of current revisions for this page:

0 comments

Add a comment