Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
add objects on loop
(version: 2)
Comparing performance of:
assign vs spread vs mutable assign vs lodash merge
Created:
3 months ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<!--your https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.jspreparation HTML code goes here--> <script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js'></script>
Script Preparation code:
/*your preparation JavaScript code goes here To execute async code during the script preparation, wrap it as function globalMeasureThatScriptPrepareFunction, example:*/
Tests:
assign
const BASE_OBJECTS = (() => { const arr = new Array(10000); for (let i = 0; i < 10000; i++) { arr[i] = { id: i, name: "obj_" + i, value: i * 2, active: i % 2 === 0 }; } return arr; })(); let result; for (let round = 0; round < 10; round++) { result = new Array(BASE_OBJECTS.length); for (let i = 0; i < BASE_OBJECTS.length; i++) { result[i] = Object.assign( {}, BASE_OBJECTS[i], { extra1: i, extra2: i + 1, extra3: i + 2 } ); } }
spread
const BASE_OBJECTS = (() => { const arr = new Array(10000); for (let i = 0; i < 10000; i++) { arr[i] = { id: i, name: "obj_" + i, value: i * 2, active: i % 2 === 0 }; } return arr; })(); let result; for (let round = 0; round < 10; round++) { result = new Array(BASE_OBJECTS.length); for (let i = 0; i < BASE_OBJECTS.length; i++) { result[i] = { ...BASE_OBJECTS[i], extra1: i, extra2: i + 1, extra3: i + 2 }; } }
mutable assign
const BASE_OBJECTS = (() => { const arr = new Array(10000); for (let i = 0; i < 10000; i++) { arr[i] = { id: i, name: "obj_" + i, value: i * 2, active: i % 2 === 0 }; } return arr; })(); let result; for (let round = 0; round < 10; round++) { result = new Array(BASE_OBJECTS.length); for (let i = 0; i < BASE_OBJECTS.length; i++) { result[i] = Object.assign( BASE_OBJECTS[i], { extra1: i, extra2: i + 1, extra3: i + 2 } ); } }
lodash merge
const BASE_OBJECTS = (() => { const arr = new Array(10000); for (let i = 0; i < 10000; i++) { arr[i] = { id: i, name: "obj_" + i, value: i * 2, active: i % 2 === 0 }; } return arr; })(); let result; for (let round = 0; round < 10; round++) { result = new Array(BASE_OBJECTS.length); for (let i = 0; i < BASE_OBJECTS.length; i++) { result[i] = _.merge({}, BASE_OBJECTS[i], { extra1: i, extra2: i + 1, extra3: i + 2 } ); } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
assign
spread
mutable assign
lodash merge
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
3 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36
Browser/OS:
Chrome 144 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
assign
204.9 Ops/sec
spread
809.9 Ops/sec
mutable assign
338.7 Ops/sec
lodash merge
29.2 Ops/sec
Related benchmarks:
js 1 foreach
trdyfuge564rdftuystredyfu
Lodash.get with instance default
Get object values
object iteration pravin
Set x includes x includes (lodash)
lodash performance
lodash performance v2
Lodash isString fork
Comments
Confirm delete:
Do you really want to delete benchmark?