Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
JavaScript shallow copy spread operator vs Object.assign performance 2X
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36
Browser:
Chrome 119
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
Using the spread operator
861337.3 Ops/sec
Using Object.assign
473019.6 Ops/sec
Script Preparation code:
window.objectToCopy = { sampleString1: 'Hello world', sampleNumber1: 123456789, sampleArray1: ['hello', 'world', 'how', 'are', 'you'], sampleString2: 'Hello world', sampleNumber2: 123456789, sampleArray2: ['hello', 'world', 'how', 'are', 'you'], sampleString3: 'Hello world', sampleNumber3: 123456789, sampleArray3: ['hello', 'world', 'how', 'are', 'you'], sampleString4: 'Hello world', sampleNumber4: 123456789, sampleArray4: ['hello', 'world', 'how', 'are', 'you'], sampleString5: 'Hello world', sampleNumber5: 123456789, sampleArray5: ['hello', 'world', 'how', 'are', 'you'], sampleString6: 'Hello world', sampleNumber6: 123456789, sampleArray6: ['hello', 'world', 'how', 'are', 'you'], sampleString7: 'Hello world', sampleNumber7: 123456789, sampleArray7: ['hello', 'world', 'how', 'are', 'you'], sampleString8: 'Hello world', sampleNumber8: 123456789, sampleArray8: ['hello', 'world', 'how', 'are', 'you'], sampleString9: 'Hello world', sampleNumber9: 123456789, sampleArray9: ['hello', 'world', 'how', 'are', 'you'], sampleString10: 'Hello world', sampleNumber10: 123456789, sampleArray10: ['hello', 'world', 'how', 'are', 'you'], } window.objectToCopy2 = { xsampleString1: 'Hello world', xsampleNumber1: 123456789, xsampleArray1: ['hello', 'world', 'how', 'are', 'you'], xsampleString2: 'Hello world', xsampleNumber2: 123456789, xsampleArray2: ['hello', 'world', 'how', 'are', 'you'], xsampleString3: 'Hello world', xsampleNumber3: 123456789, xsampleArray3: ['hello', 'world', 'how', 'are', 'you'], xsampleString4: 'Hello world', xsampleNumber4: 123456789, xsampleArray4: ['hello', 'world', 'how', 'are', 'you'], xsampleString5: 'Hello world', xsampleNumber5: 123456789, xsampleArray5: ['hello', 'world', 'how', 'are', 'you'], xsampleString6: 'Hello world', xsampleNumber6: 123456789, xsampleArray6: ['hello', 'world', 'how', 'are', 'you'], xsampleString7: 'Hello world', xsampleNumber7: 123456789, xsampleArray7: ['hello', 'world', 'how', 'are', 'you'], xsampleString8: 'Hello world', xsampleNumber8: 123456789, xsampleArray8: ['hello', 'world', 'how', 'are', 'you'], xsampleString9: 'Hello world', xsampleNumber9: 123456789, xsampleArray9: ['hello', 'world', 'how', 'are', 'you'], xsampleString10: 'Hello world', xsampleNumber10: 123456789, xsampleArray10: ['hello', 'world', 'how', 'are', 'you'], }
Tests:
Using the spread operator
const object = window.objectToCopy const object2 = window.objectToCopy2 const finalObject = { ...object,...object2, };
Using Object.assign
const object = window.objectToCopy const object2 = window.objectToCopy2 const finalObject = Object.assign({}, object, object2);