deep copy vs cheating
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var a = [{test: true}, 3, "dkfjdl", [3,4,5]];
function deepCopy(obj) {
if (Object.prototype.toString.call(obj) === '[object Array]') {
var out = [], i = 0, len = obj.length;
for ( ; i < len; i++ ) {
out[i] = arguments.callee(obj[i]);
}
return out;
}
if (typeof obj === 'object') {
var out = {}, i;
for ( i in obj ) {
out[i] = arguments.callee(obj[i]);
}
return out;
}
return obj;
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Deep Copy |
|
pending… |
Cheating |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments