5cp
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
function copyFive(obj, a, b, c, d, e, f) {
obj = obj || {};
if (window.__DEV__) {
if (f) {
throw new Error('Too many');
}
}
var args = [a, b, c, d, e];
var ii = 0,
v;
while (args[ii]) {
v = args[ii++];
for (var k in v) {
obj[k] = v[k];
}
if (v.hasOwnProperty && v.hasOwnProperty('toString') && (typeof v.toString != 'undefined') && (obj.toString !== v.toString)) {
obj.toString = v.toString;
}
}
return obj;
}
function copyWhatever(obj) {
obj = obj || {};
if (window.__DEV__) {
if (f) {
throw new Error('Too many arguments passed to copyProperties');
}
}
var args = arguments;
var ii = 1,
v;
while (args[ii]) {
v = args[ii++];
for (var k in v) {
obj[k] = v[k];
}
if (v.hasOwnProperty && v.hasOwnProperty('toString') && (typeof v.toString != 'undefined') && (obj.toString !== v.toString)) {
obj.toString = v.toString;
}
}
return obj;
}
var o = {
name: "Kirk",
family: "Hammet",
plays: function() {
return "mewawwwyee";
}
};
var a = {aa:1,ab:2,ac:3};
var b = {ab:1,bb:2,bc:3};
var c = {ca:1,cb:2,cc:3};
var d = {da:1,db:2,dc:3};
var e = {ea:1,eb:2,ec:3};
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
five_one |
|
pending… |
arg_one |
|
pending… |
five_five |
|
pending… |
args_five |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments