copy array vs inherit its props

JavaScript performance comparison

Test case created

Info

at what point is it cheaper to inherit properties than copy them for arrays

Preparation code

<script>
var small_array = [1,2,3,4,5];
var medium_array = []
var large_array = []
for (var i=0;i<100;i++)medium_array.push(i);
for (var i=0;i<1000;i++)large_array.push(i);
function copy(array){
  var i = array.length
  var res = {length:i}
  while(i--) res[i] = array[i];
  return res
}
</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
inherit
Object.create(medium_array);
pending…
small copy
copy(small_array);
pending…
medium copy
copy(medium_array);
pending…
large copy
copy(large_array);
pending…
medium slice
medium_array.slice();
pending…
small slice
small_array.slice();
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