arraycopy

JavaScript performance comparison

Test case created by Dan Rzeppa

Info

Testing different ways of copying arrays.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var dstAry = []
    var srcAry1 = ["abcdefghi", "jklmnopqrstuv", "wxyz"]
    var srcAry2 = ["zyxwvut"]
    var srcAry3 = ["srqponml", "kjihgfedcba"]
   
    function inPlace(dst, src) {
      dst.length = src.length
      for (var i = 0, len = src.length; i < len; i++) {
        dst[i] = src[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
Slice
dstAry = srcAry1.slice(0)
dstAry = srcAry2.slice(0)
dstAry = srcAry3.slice(0)
pending…
In Place
inPlace(dstAry,srcAry1)
inPlace(dstAry,srcAry2)
inPlace(dstAry,srcAry3)
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