Int8Array set vs manual concat

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var a = new Int8Array( [ 1, 2, 3 ] );
    var b = new Int8Array( [ 4, 5, 6 ] );
    function concat(a,b){
        var c = new Array();
        for(var i = 0; i < a.length; i++){
            c.push(a[i])
        }
        for(var i = 0; i < b.length; i++){
            c.push(b[i])
        }
        return c;
    }
   
    function set(a,b){
        var c = new Int8Array(a.length + b.length);
        c.set(a);
        c.set(b, a.length);
        return c;
    }
};
</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
Set
console.log(set(a,b));
pending…
Concat

console.log(concat(a,b));
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

Add a comment