Array Buffer vs Array

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var buffer = new ArrayBuffer(1000 * 4);
    var intView = new Uint32Array(buffer);
    var floatView = new Float32Array(buffer);
    var plainArray = new Array(1000);
   
    var floatSource = [];
    for(var i = 0; i < 1000; i++) floatSource[i] = Math.random();
   
    var intSource = [];
    for(var i = 0; i < 1000; i++) intSource[i] = Math.floor(1000 * Math.random());
};
</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
Write Uint32Array Loop
for(var i = 0; i < intSource.length; i++) intView[i] = intSource[i];
pending…
Write Uint32Array Set
intView.set(intSource);
pending…
Write Float32Array Loop
for(var i = 0; i < floatSource.length; i++) floatView[i] = floatSource[i];
pending…
Write Float32Array Set
floatView.set(floatSource);
pending…
Plain Array Copy Loop
for(var i = 0; i < floatSource.length; i++) plainArray[i] = floatSource[i];
pending…
Plain Array Slice
plainArray = floatSource.slice(0);
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