copy array vs inherit its props
JavaScript performance comparison
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.
| Test | Ops/sec | |
|---|---|---|
inherit |
|
pending… |
small copy |
|
pending… |
medium copy |
|
pending… |
large copy |
|
pending… |
medium slice |
|
pending… |
small slice |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments