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; rv:138.0) Gecko/20100101 Firefox/138.0
Browser:
Firefox 138
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
window.structuredClone
234350.3 Ops/sec
Spread syntax
3055664.0 Ops/sec
Object assign
8810644.0 Ops/sec
babyClone
817323.4 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);