Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Object.assign vs. JSON String/Parse vs deepclone
Creating a "new" object reference every time
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/143.0.0.0 Safari/537.36 Edg/143.0.0.0
Browser:
Chrome 143
Operating system:
Windows
Device Platform:
Desktop
Date tested:
4 months ago
Test name
Executions per second
deepclone
38459496.0 Ops/sec
JSON Parse
64580096.0 Ops/sec
Object.assign
97911848.0 Ops/sec
Tests:
deepclone
function deepClone(obj) { if (obj === null || typeof obj !== 'object') { return obj; } const clone = Array.isArray(obj) ? [] : {}; for (let key in obj) { if (obj.hasOwnProperty(key)) { clone[key] = deepClone(obj[key]); } } return clone; } var n = {foo: 'bar', hello: [{hello: 'world', foo: 'bar'},{hello: 'world', foo: 'bar'},{hello: 'world', foo: 'bar'},{hello: 'world', foo: 'bar'}]}; while (n.length < 1000) { n = deepClone(n); }
JSON Parse
var n = {foo: 'bar', hello: [{hello: 'world', foo: 'bar'},{hello: 'world', foo: 'bar'},{hello: 'world', foo: 'bar'},{hello: 'world', foo: 'bar'}]}; while(n.length < 1000) { n = JSON.parse(JSON.stringify(n)) }
Object.assign
var n = {foo: 'bar', hello: [{hello: 'world', foo: 'bar'},{hello: 'world', foo: 'bar'},{hello: 'world', foo: 'bar'},{hello: 'world', foo: 'bar'}]}; while(n.length < 1000) { n = Object.assign({}, n); }