object spread vs polyfill
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var a = {one:1, two:2, three:3, four:4, five:5, six:6, seven:7};
var b;
function import$(obj, src){
var own = {}.hasOwnProperty;
for (var key in src) if (own.call(src, key)) obj[key] = src[key];
return obj;
}
function import$$(obj, src) {
for (var key in src) {
if (obj.hasOwnProperty(key)) {
obj[key] = src[key];
}
}
return obj;
}
function import$$$(obj, src) {
for (var key in src) {
if (Object.hasOwnProperty.call(obj, key)) {
obj[key] = src[key];
}
}
return obj;
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
Test | Ops/sec | |
---|---|---|
native spread
|
|
pending… |
polyfill
|
|
pending… |
Object.assign
|
|
pending… |
polyfill 2
|
|
pending… |
polyfill 3
|
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit
to the URL.
0 Comments