Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
inbuilt structuredClone vs deepClone
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:120.0) Gecko/20100101 Firefox/120.0
Browser:
Firefox 120
Operating system:
Linux
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
structuredClone
160076.8 Ops/sec
deepClone https://github.com/nodejs/node/issues/34355#issuecomment-658394617
1502680.6 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": [], "deepvalue": {"this": "that"}, "startDate": "2020-10-21T00:00:00.000Z", "endDate": "2020-10-21T00:00:00.000Z", "applyed": false } function deepClone(o) { if (typeof o !== "object") { return o } if (!o) { return o } // https://jsperf.com/deep-copy-vs-json-stringify-json-parse/25 if (Array.isArray(o)) { const newO = [] for (let i = 0; i < o.length; i += 1) { const val = !o[i] || typeof o[i] !== "object" ? o[i] : deepClone(o[i]) newO[i] = val === undefined ? null : val } return newO } const newO = {} for (const i of Object.keys(o)) { const val = !o[i] || typeof o[i] !== "object" ? o[i] : deepClone(o[i]) if (val === undefined) { continue } newO[i] = val } return newO }
Tests:
structuredClone
const copy = structuredClone(voucher);
deepClone https://github.com/nodejs/node/issues/34355#issuecomment-658394617
const copy = deepClone(voucher);