Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
object copy bench
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser:
Chrome 121
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
window.structuredClone
289001.7 Ops/sec
Spread syntax
15099320.0 Ops/sec
Object assign
3037711.0 Ops/sec
babyClone
375198.8 Ops/sec
Script Preparation code:
var voucher = { "single": false, "applyOverTaxes": false, "discountType": "1", "value": 100, "minimumAmount": 0, "quantity": 1, "suffixLength": 8, "code": "IF5R0AFX", "vertical": [], "allowedPaymentMethods": [], "allowedBanks": [], "types": [], "partners": [], "startDate": "2020-10-21T00:00:00.000Z", "endDate": "2020-10-21T00:00:00.000Z", "applyed": false } function babyClone(obj) { switch (typeof obj) { case 'string': case 'number': case 'bigint': case 'boolean': case 'symbol': case 'undefined': return obj; case 'object': if (!obj) return null; if (Array.isArray(obj)) { return Array.prototype.map.call(obj, babyClone); } if (Object.getPrototypeOf(obj) !== Object.getPrototypeOf({})) { // this won't catch Proxy throw 'trying to copy a class instance'; } let copy = {}; for (let sym of Object.getOwnPropertySymbols(obj)) { copy[sym] = babyClone(obj[sym]); } for (let key in obj) { copy[key] = babyClone(obj[key]); } return copy; case 'function': throw 'no copying things with functions in them'; default: throw 'what new nonsense have they added to js'; } }
Tests:
window.structuredClone
const copy = window.structuredClone(voucher);
Spread syntax
const copy = { ...voucher };
Object assign
const copy = {}; Object.assign(copy, voucher);
babyClone
const copy = babyClone(voucher);