Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash vs JSON vs Ramda Clone vs fixed old school ugly with moar json
(version: 0)
just benchmarking things
Comparing performance of:
Lodash cloneDeep vs Json clone vs Ramda clone vs hand rolled vs loop not map (still recursive) vs original gangster
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
Script Preparation code:
var MyObject = [ { "_id": "5e1e19a37db52f9e9d93e658", "index": 0, "guid": "396e60ae-845d-4503-b494-2a0ccd1df9f2", "isActive": false, "balance": "$1,389.79", "picture": "http://placehold.it/32x32", "age": 26, "eyeColor": "green", "name": "Josie Head", "gender": "female", "company": "FITCORE", "email": "josiehead@fitcore.com", "phone": "+1 (960) 535-2795", "address": "846 Regent Place, Twilight, Missouri, 5131", "about": "Duis adipisicing commodo reprehenderit veniam cillum nostrud sit sunt est. Tempor laborum pariatur irure nulla ex reprehenderit. Voluptate anim eu et nostrud ipsum mollit aute qui ea ullamco. Nulla minim sint voluptate exercitation nostrud mollit eu mollit. Ea duis dolor quis enim consectetur. Veniam cillum exercitation incididunt reprehenderit.\r\n", "registered": "2019-01-06T08:54:40 +05:00", "latitude": -80.487714, "longitude": 78.798071, "tags": [ "minim", "irure", "dolor", "commodo", "magna", "excepteur", "magna" ], "friends": [ { "id": 0, "name": "Odom Grant" }, { "id": 1, "name": "Hester Caldwell" }, { "id": 2, "name": "Clements Bullock" } ], "greeting": "Hello, Josie Head! You have 3 unread messages.", "favoriteFruit": "apple" }, { "_id": "5e1e19a38ad96c2c356f4bfb", "index": 1, "guid": "4786ea00-8742-439f-8e2a-004a2bae8a84", "isActive": true, "balance": "$2,048.19", "picture": "http://placehold.it/32x32", "age": 26, "eyeColor": "blue", "name": "Julie Kemp", "gender": "female", "company": "FUELWORKS", "email": "juliekemp@fuelworks.com", "phone": "+1 (886) 498-3935", "address": "152 Middleton Street, Celeryville, Ohio, 9868", "about": "Dolore eu do laborum irure amet nulla deserunt sunt ex et voluptate aute reprehenderit irure. Ullamco tempor aute sunt dolore nulla consequat esse est occaecat sunt non. Reprehenderit esse aute Lorem aliquip elit fugiat incididunt mollit sint qui dolore incididunt mollit. Aliquip ad mollit anim proident ipsum irure. Elit ullamco est eu sunt nostrud aliquip laboris sint reprehenderit. Aliquip anim eiusmod officia duis dolor voluptate duis nisi.\r\n", "registered": "2018-08-12T10:46:50 +04:00", "latitude": -3.524966, "longitude": -156.077579, "tags": [ "minim", "est", "Lorem", "nostrud", "enim", "non", "ea" ], "friends": [ { "id": 0, "name": "Barr Scott" }, { "id": 1, "name": "Atkinson Avery" }, { "id": 2, "name": "Teri Rivera" } ], "greeting": "Hello, Julie Kemp! You have 6 unread messages.", "favoriteFruit": "apple" }, { "_id": "5e1e19a343953743072e48c9", "index": 2, "guid": "f0b3b8a2-6383-4cfa-a95e-439d3e360592", "isActive": true, "balance": "$1,305.41", "picture": "http://placehold.it/32x32", "age": 34, "eyeColor": "green", "name": "Herman Griffith", "gender": "male", "company": "OPTICOM", "email": "hermangriffith@opticom.com", "phone": "+1 (922) 507-3579", "address": "314 Dekalb Avenue, Dixie, Minnesota, 2312", "about": "Anim mollit esse adipisicing et consectetur proident. Ut minim tempor consectetur aute eiusmod eu. Aliquip do esse pariatur aliqua non cillum. Magna sint laboris reprehenderit duis et id eu velit.\r\n", "registered": "2018-06-12T09:35:46 +04:00", "latitude": -30.773629, "longitude": -47.060717, "tags": [ "aute", "pariatur", "deserunt", "et", "cillum", "id", "excepteur" ], "friends": [ { "id": 0, "name": "Mack David" }, { "id": 1, "name": "Joanne Bryan" }, { "id": 2, "name": "Carroll Allen" } ], "greeting": "Hello, Herman Griffith! You have 6 unread messages.", "favoriteFruit": "apple" }, { "_id": "5e1e19a344109f0176249156", "index": 3, "guid": "8d123a89-ac66-40ee-9d1d-3e34d12a66c5", "isActive": true, "balance": "$1,877.60", "picture": "http://placehold.it/32x32", "age": 22, "eyeColor": "blue", "name": "Best Bruce", "gender": "male", "company": "MAINELAND", "email": "bestbruce@maineland.com", "phone": "+1 (835) 553-3427", "address": "247 Cumberland Street, Volta, Rhode Island, 6571", "about": "Fugiat velit id veniam ut culpa aliqua dolore excepteur fugiat fugiat Lorem irure. Consectetur anim pariatur eu irure et. Elit anim voluptate magna ut minim labore. Occaecat qui pariatur ea quis Lorem consectetur aute labore aliqua ut aute irure sunt. Tempor eu pariatur sint excepteur exercitation aliqua aliquip proident deserunt. Incididunt dolore proident est ex ipsum.\r\n", "registered": "2016-09-03T02:40:47 +04:00", "latitude": -86.651356, "longitude": -72.364284, "tags": [ "exercitation", "dolor", "duis", "tempor", "ea", "ut", "enim" ], "friends": [ { "id": 0, "name": "Bolton Peters" }, { "id": 1, "name": "Lucinda Franklin" }, { "id": 2, "name": "Humphrey Gentry" } ], "greeting": "Hello, Best Bruce! You have 4 unread messages.", "favoriteFruit": "strawberry" }, { "_id": "5e1e19a3ebc39ce616e60e71", "index": 4, "guid": "c97a8bf9-f1d5-4d3a-9a82-1470ddb80863", "isActive": true, "balance": "$2,794.32", "picture": "http://placehold.it/32x32", "age": 21, "eyeColor": "green", "name": "Young Frederick", "gender": "female", "company": "MATRIXITY", "email": "youngfrederick@matrixity.com", "phone": "+1 (899) 577-2643", "address": "405 Bay Street, Harold, New York, 2507", "about": "Ea labore dolor est pariatur consectetur aute qui cillum voluptate. Lorem voluptate mollit consectetur in elit reprehenderit. In elit magna Lorem dolore nostrud ut in ad pariatur id. Nisi eiusmod pariatur ut labore. Anim elit do excepteur ex mollit ad labore excepteur aliquip. Ipsum cillum mollit aute ad elit esse esse et eu anim veniam.\r\n", "registered": "2017-04-26T12:04:12 +04:00", "latitude": -6.274446, "longitude": -177.658413, "tags": [ "sit", "sunt", "pariatur", "commodo", "adipisicing", "non", "enim" ], "friends": [ { "id": 0, "name": "Latasha Mclean" }, { "id": 1, "name": "Dillard Barrera" }, { "id": 2, "name": "Roth Acevedo" } ], "greeting": "Hello, Young Frederick! You have 5 unread messages.", "favoriteFruit": "strawberry" }, { "_id": "5e1e19a3f36e5a3ff58c3f1e", "index": 5, "guid": "2c41264a-f19e-4fa5-91d7-ca8cf5314b0a", "isActive": true, "balance": "$2,323.64", "picture": "http://placehold.it/32x32", "age": 22, "eyeColor": "blue", "name": "Cotton Warner", "gender": "male", "company": "EQUITAX", "email": "cottonwarner@equitax.com", "phone": "+1 (871) 439-2340", "address": "517 Madoc Avenue, Chloride, Utah, 9942", "about": "Aute esse adipisicing fugiat sunt. Ullamco est officia ex quis fugiat nostrud Lorem consectetur minim aliqua incididunt tempor dolore. Anim duis consectetur commodo Lorem proident id elit reprehenderit velit mollit aute non elit est. Tempor do occaecat officia est fugiat qui laborum ad do magna.\r\n", "registered": "2018-10-20T10:42:15 +04:00", "latitude": 47.224342, "longitude": 84.61698, "tags": [ "mollit", "fugiat", "sint", "nisi", "sit", "aliquip", "deserunt" ], "friends": [ { "id": 0, "name": "Jodi Long" }, { "id": 1, "name": "Jenifer Willis" }, { "id": 2, "name": "Kirsten Roberts" } ], "greeting": "Hello, Cotton Warner! You have 6 unread messages.", "favoriteFruit": "banana" }, { "_id": "5e1e19a358fd18301abe8d8d", "index": 6, "guid": "8a590918-c40e-4291-8e16-5919c01ce395", "isActive": false, "balance": "$1,809.92", "picture": "http://placehold.it/32x32", "age": 33, "eyeColor": "green", "name": "Margo Nash", "gender": "female", "company": "FROLIX", "email": "margonash@frolix.com", "phone": "+1 (889) 407-3670", "address": "916 Colonial Road, Belfair, Connecticut, 1956", "about": "Amet ullamco aliqua occaecat nulla laborum incididunt minim nostrud sint. Eiusmod ut labore adipisicing commodo consectetur. Id cupidatat proident officia do. Aute nostrud sit pariatur irure consequat esse enim magna nisi. Magna ad cupidatat cupidatat amet nisi incididunt quis enim in aliquip ut velit sint aliquip.\r\n", "registered": "2015-06-08T03:26:01 +04:00", "latitude": -69.241111, "longitude": -40.43834, "tags": [ "ullamco", "commodo", "deserunt", "sint", "consectetur", "pariatur", "ullamco" ], "friends": [ { "id": 0, "name": "Malinda Lang" }, { "id": 1, "name": "Jeanie Rivers" }, { "id": 2, "name": "Greene Wilkerson" } ], "greeting": "Hello, Margo Nash! You have 6 unread messages.", "favoriteFruit": "banana" } ]; var myCopy = null;
Tests:
Lodash cloneDeep
myCopy = _.cloneDeep(MyObject);
Json clone
myCopy = JSON.parse(JSON.stringify(MyObject));
Ramda clone
myCopy = R.clone(MyObject);
hand rolled
const cp=(obj)=>"object" === typeof obj ? Object.fromEntries(Object.entries(obj).map(([k,v])=>[k,cp(v)])) : obj myCopy = cp(MyObject)
loop not map (still recursive)
const cp_old=(obj)=>{ if ("object" !== typeof obj) { return obj } else { const entries = Object.entries(obj) for(let i = 0; i < entries.length; i++) { entries[i][2] = cp_old(entries[i][2]) } return Object.fromEntries(entries) } } myCopy = cp_old(MyObject)
original gangster
const cp_stack=(obj)=>{ if ("object" !== typeof obj) { return obj } else { const stack = [] let entries = Object.entries(obj) let i=0 stackloop: while(true) { for(; i < entries.length; i++) { const entry = entries[i][2] if ("object" !== typeof entry) continue else { stack.push([i,entries]) entries = Object.entries(entries[i][2]) i = 0 continue stackloop } } if (stack.length === 0) break const copy = entries [i, entries] = stack.pop() entries[i][2] = copy } return Object.fromEntries(entries) } } myCopy = cp_stack(MyObject)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (6)
Previous results
Fork
Test case name
Result
Lodash cloneDeep
Json clone
Ramda clone
hand rolled
loop not map (still recursive)
original gangster
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
It looks like we have some benchmarking results! To provide a meaningful answer, I'd need to analyze the test names and the relative performance of each method. Here's my interpretation: * The "original gangster" method appears to be the most efficient, with an execution rate of 62702.546875 exec/sec. * The "loop not map (still recursive)" method is significantly slower than the "original gangster" method, but still relatively efficient, with an execution rate of 36684.12890625 exec/sec. * The other methods ("Json clone", "Lodash cloneDeep", "hand rolled", and "Ramda clone") are slower than both of these methods, suggesting that they may be less efficient due to various factors such as algorithmic complexity or implementation details. Without more context or information about the specific use cases for each method, it's difficult to provide a definitive conclusion. However, based on this analysis, it seems that the "original gangster" method is likely the most efficient solution for shallow object cloning in JavaScript.
Related benchmarks:
Lodash cloneDeep vs JSON Clone (Large Object 2)
Lodash cloneDeep vs JSON Clone large Json
Lodash vs JSON vs Ramda Clone vs old school ugly with moar json
Lodash(v4.17.21) cloneDeep vs JSON Clone Larger object
Comments
Confirm delete:
Do you really want to delete benchmark?