Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
test 4bc5a6e8-e19c-46c7-8c39-c70b7152fe5f
(version: 0)
Comparing performance of:
json.stringify vs custom
Created:
7 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var date1 = new Date(Date.parse('2018-11-07')); window.obj1 = [ { "_id": "5be32291a9aa8507633f4a2b", "index": 0, "guid": "a6d3c376-5cd1-4d0b-8634-e46e30ef74ef", "isActive": true, "balance": "$2,110.42", "picture": "http://placehold.it/32x32", "age": 21, "eyeColor": "green", "name": "Annie Mccormick", "gender": "female", "company": "BUZZOPIA", "email": "anniemccormick@buzzopia.com", "phone": "+1 (912) 548-3160", "address": "184 Clarendon Road, Brandermill, Kentucky, 5053", "about": "Dolore Lorem ipsum laboris enim magna esse dolore voluptate do aliqua Lorem. Incididunt aute sunt fugiat labore nisi incididunt. Eiusmod commodo reprehenderit dolor sunt deserunt. Aliquip excepteur quis eiusmod fugiat deserunt tempor aliqua consectetur. Magna velit voluptate amet magna qui enim aute sunt culpa excepteur non. Eu ipsum ea anim tempor aute culpa id quis anim velit laboris mollit exercitation minim.\r\n", "registered": "2015-09-25T05:15:31 -05:00", "latitude": 65.326298, "longitude": -115.15695, "tags": [ "irure", "labore", "fugiat", "veniam", "qui", "aliqua", "do" ], "friends": [ { "id": 0, "name": "Evans Powell" }, { "id": 1, "name": "Conrad Benson" }, { "id": 2, "name": "Sylvia Long" } ], "greeting": "Hello, Annie Mccormick! You have 2 unread messages.", "favoriteFruit": "strawberry" }, { "_id": "5be32291b527b3fdca8cce38", "index": 1, "guid": "164f2d88-ebdd-4a8d-a327-06578138eaef", "isActive": false, "balance": "$1,637.30", "picture": "http://placehold.it/32x32", "age": 20, "eyeColor": "green", "name": "Mara Schroeder", "gender": "female", "company": "ENERSAVE", "email": "maraschroeder@enersave.com", "phone": "+1 (885) 573-2177", "address": "111 Waldorf Court, Rose, Wyoming, 5585", "about": "Magna fugiat in laboris culpa non occaecat exercitation tempor sunt excepteur laborum. Nisi ad exercitation culpa magna sint sint ad voluptate commodo in nostrud consequat. Ad nostrud ipsum quis tempor dolor et excepteur deserunt Lorem. Aliqua ad veniam ad minim. Veniam cupidatat dolore quis irure non esse esse eiusmod sint mollit deserunt.\r\n", "registered": "2015-05-09T08:30:41 -05:00", "latitude": -15.300284, "longitude": -140.125254, "tags": [ "deserunt", "ipsum", "et", "elit", "proident", "fugiat", "id" ], "friends": [ { "id": 0, "name": "Bond Pugh" }, { "id": 1, "name": "Wolfe Gardner" }, { "id": 2, "name": "Alta Stevens" } ], "greeting": "Hello, Mara Schroeder! You have 5 unread messages.", "favoriteFruit": "banana" }, { "_id": "5be322918366377676420e3b", "index": 2, "guid": "616dd858-6262-48b7-92bc-fcb94d75afd0", "isActive": true, "balance": "$1,437.90", "picture": "http://placehold.it/32x32", "age": 30, "eyeColor": "blue", "name": "Melody Morse", "gender": "female", "company": "DATAGEN", "email": "melodymorse@datagen.com", "phone": "+1 (825) 593-3734", "address": "377 Schweikerts Walk, Hondah, Ohio, 7957", "about": "Consectetur aliquip officia duis nulla commodo aliquip fugiat elit. Reprehenderit tempor deserunt nisi ipsum minim consequat veniam dolore. Tempor sit cupidatat dolore et consequat eiusmod incididunt ullamco. Dolore adipisicing et labore ipsum laboris.\r\n", "registered": "2016-08-25T11:22:08 -05:00", "latitude": 51.486081, "longitude": 57.847242, "tags": [ "occaecat", "duis", "occaecat", "mollit", "ipsum", "ad", "exercitation" ], "friends": [ { "id": 0, "name": "Leah Rodriguez" }, { "id": 1, "name": "Sharon Holman" }, { "id": 2, "name": "Saundra Valentine" } ], "greeting": "Hello, Melody Morse! You have 4 unread messages.", "favoriteFruit": "banana" }, { "_id": "5be322918ffc6e662ae2e650", "index": 3, "guid": "0fca4df8-93f2-4573-a0a5-ed3c7863a741", "isActive": false, "balance": "$3,813.99", "picture": "http://placehold.it/32x32", "age": 23, "eyeColor": "blue", "name": "Sheree Ayala", "gender": "female", "company": "STREZZO", "email": "shereeayala@strezzo.com", "phone": "+1 (882) 576-3963", "address": "987 Hanover Place, Geyserville, Arizona, 7482", "about": "Dolor Lorem labore anim ipsum velit adipisicing aliquip proident tempor dolor anim incididunt. Do ea ad sit cupidatat elit consequat. Mollit tempor proident nulla nisi voluptate laborum.\r\n", "registered": "2015-07-16T02:08:32 -05:00", "latitude": 84.43454, "longitude": -94.209983, "tags": [ "amet", "adipisicing", "non", "labore", "elit", "nisi", "consequat" ], "friends": [ { "id": 0, "name": "Celia Frye" }, { "id": 1, "name": "Bass Benton" }, { "id": 2, "name": "Ila Schultz" } ], "greeting": "Hello, Sheree Ayala! You have 5 unread messages.", "favoriteFruit": "apple" }, { "_id": "5be322926d7dc656ca87b1b1", "index": 4, "guid": "d8fa2c11-8749-4743-a1d7-4a67491511a2", "isActive": true, "balance": "$2,984.00", "picture": "http://placehold.it/32x32", "age": 29, "eyeColor": "green", "name": "Janell Luna", "gender": "female", "company": "HOMELUX", "email": "janellluna@homelux.com", "phone": "+1 (942) 568-2578", "address": "415 Allen Avenue, Ada, Northern Mariana Islands, 7996", "about": "Quis minim amet velit culpa est veniam nostrud est esse anim sit adipisicing elit. Velit ea veniam et ea in ut do occaecat. Do duis id ut cillum irure labore laborum consectetur amet occaecat ullamco sunt minim nisi. Eu commodo laboris ad consequat occaecat.\r\n", "registered": "2017-10-09T08:53:24 -05:00", "latitude": -84.960732, "longitude": -92.028867, "tags": [ "quis", "est", "amet", "est", "in", "ullamco", "sint" ], "friends": [ { "id": 0, "name": "Wyatt Farmer" }, { "id": 1, "name": "Bradford Serrano" }, { "id": 2, "name": "English Rasmussen" } ], "greeting": "Hello, Janell Luna! You have 1 unread messages.", "favoriteFruit": "apple" } ]; window.obj2 = [ { "_id": "5be32291a9aa8507633f4a2b", "index": 0, "guid": "a6d3c376-5cd1-4d0b-8634-e46e30ef74ef", "isActive": true, "balance": "$2,110.42", "picture": "http://placehold.it/32x32", "age": 21, "eyeColor": "green", "name": "Annie Mccormick", "gender": "female", "company": "BUZZOPIA", "email": "anniemccormick@buzzopia.com", "phone": "+1 (912) 548-3160", "address": "184 Clarendon Road, Brandermill, Kentucky, 5053", "about": "Dolore Lorem ipsum laboris enim magna esse dolore voluptate do aliqua Lorem. Incididunt aute sunt fugiat labore nisi incididunt. Eiusmod commodo reprehenderit dolor sunt deserunt. Aliquip excepteur quis eiusmod fugiat deserunt tempor aliqua consectetur. Magna velit voluptate amet magna qui enim aute sunt culpa excepteur non. Eu ipsum ea anim tempor aute culpa id quis anim velit laboris mollit exercitation minim.\r\n", "registered": "2015-09-25T05:15:31 -05:00", "latitude": 65.326298, "longitude": -115.15695, "tags": [ "irure", "labore", "fugiat", "veniam", "qui", "aliqua", "do" ], "friends": [ { "id": 0, "name": "Evans Powell" }, { "id": 1, "name": "Conrad Benson" }, { "id": 2, "name": "Sylvia Long" } ], "greeting": "Hello, Annie Mccormick! You have 2 unread messages.", "favoriteFruit": "strawberry" }, { "_id": "5be32291b527b3fdca8cce38", "index": 1, "guid": "164f2d88-ebdd-4a8d-a327-06578138eaef", "isActive": false, "balance": "$1,637.30", "picture": "http://placehold.it/32x32", "age": 20, "eyeColor": "green", "name": "Mara Schroeder", "gender": "female", "company": "ENERSAVE", "email": "maraschroeder@enersave.com", "phone": "+1 (885) 573-2177", "address": "111 Waldorf Court, Rose, Wyoming, 5585", "about": "Magna fugiat in laboris culpa non occaecat exercitation tempor sunt excepteur laborum. Nisi ad exercitation culpa magna sint sint ad voluptate commodo in nostrud consequat. Ad nostrud ipsum quis tempor dolor et excepteur deserunt Lorem. Aliqua ad veniam ad minim. Veniam cupidatat dolore quis irure non esse esse eiusmod sint mollit deserunt.\r\n", "registered": "2015-05-09T08:30:41 -05:00", "latitude": -15.300284, "longitude": -140.125254, "tags": [ "deserunt", "ipsum", "et", "elit", "proident", "fugiat", "id" ], "friends": [ { "id": 0, "name": "Bond Pugh" }, { "id": 1, "name": "Wolfe Gardner" }, { "id": 2, "name": "Alta Stevens" } ], "greeting": "Hello, Mara Schroeder! You have 5 unread messages.", "favoriteFruit": "banana" }, { "_id": "5be322918366377676420e3b", "index": 2, "guid": "616dd858-6262-48b7-92bc-fcb94d75afd0", "isActive": true, "balance": "$1,437.90", "picture": "http://placehold.it/32x32", "age": 30, "eyeColor": "blue", "name": "Melody Morse", "gender": "female", "company": "DATAGEN", "email": "melodymorse@datagen.com", "phone": "+1 (825) 593-3734", "address": "377 Schweikerts Walk, Hondah, Ohio, 7957", "about": "Consectetur aliquip officia duis nulla commodo aliquip fugiat elit. Reprehenderit tempor deserunt nisi ipsum minim consequat veniam dolore. Tempor sit cupidatat dolore et consequat eiusmod incididunt ullamco. Dolore adipisicing et labore ipsum laboris.\r\n", "registered": "2016-08-25T11:22:08 -05:00", "latitude": 51.486081, "longitude": 57.847242, "tags": [ "occaecat", "duis", "occaecat", "mollit", "ipsum", "ad", "exercitation" ], "friends": [ { "id": 0, "name": "Leah Rodriguez" }, { "id": 1, "name": "Sharon Holman" }, { "id": 2, "name": "Saundra Valentine" } ], "greeting": "Hello, Melody Morse! You have 4 unread messages.", "favoriteFruit": "banana" }, { "_id": "5be322918ffc6e662ae2e650", "index": 3, "guid": "0fca4df8-93f2-4573-a0a5-ed3c7863a741", "isActive": false, "balance": "$3,813.99", "picture": "http://placehold.it/32x32", "age": 23, "eyeColor": "blue", "name": "Sheree Ayala", "gender": "female", "company": "STREZZO", "email": "shereeayala@strezzo.com", "phone": "+1 (882) 576-3963", "address": "987 Hanover Place, Geyserville, Arizona, 7482", "about": "Dolor Lorem labore anim ipsum velit adipisicing aliquip proident tempor dolor anim incididunt. Do ea ad sit cupidatat elit consequat. Mollit tempor proident nulla nisi voluptate laborum.\r\n", "registered": "2015-07-16T02:08:32 -05:00", "latitude": 84.43454, "longitude": -94.209983, "tags": [ "amet", "adipisicing", "non", "labore", "elit", "nisi", "consequat" ], "friends": [ { "id": 0, "name": "Celia Frye" }, { "id": 1, "name": "Bass Benton" }, { "id": 2, "name": "Ila Schultz" } ], "greeting": "Hello, Sheree Ayala! You have 5 unread messages.", "favoriteFruit": "apple" }, { "_id": "5be322926d7dc656ca87b1b1", "index": 4, "guid": "d8fa2c11-8749-4743-a1d7-4a67491511a2", "isActive": true, "balance": "$2,984.00", "picture": "http://placehold.it/32x32", "age": 29, "eyeColor": "green", "name": "Janell Luna", "gender": "female", "company": "HOMELUX", "email": "janellluna@homelux.com", "phone": "+1 (942) 568-2578", "address": "415 Allen Avenue, Ada, Northern Mariana Islands, 7996", "about": "Quis minim amet velit culpa est veniam nostrud est esse anim sit adipisicing elit. Velit ea veniam et ea in ut do occaecat. Do duis id ut cillum irure labore laborum consectetur amet occaecat ullamco sunt minim nisi. Eu commodo laboris ad consequat occaecat.\r\n", "registered": "2017-10-09T08:53:24 -05:00", "latitude": -84.960732, "longitude": -92.028867, "tags": [ "quis", "est", "amet", "est", "in", "ullamco", "sint" ], "friends": [ { "id": 0, "name": "Wyatt Farmer" }, { "id": 1, "name": "Bradford Serrano" }, { "id": 2, "name": "English Rasmussen" } ], "greeting": "Hello, Janell Luna! You have 1 unread messages.", "favoriteFruit": "apple" } ]; function isFunction(functionToCheck) { var getType = {}; return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]'; } function objectsAreEqual1(first, second) { return JSON.stringify(first) === JSON.stringify(second); } function objectsAreEqual2(first, second) { if (first === undefined) return second === undefined; if (first === null) return second === null; if (second === undefined) return first === undefined; if (second === null) return first === null; if (isFunction(first)) return isFunction(second); else if (Array.isArray(first)) { if (!Array.isArray(second)) return false; else if (first.length !== second.length) return false; for (let i = 0; i < first.length; i++) { if (!objectsAreEqual2(first[i], second[i])) return false; } } else if (first instanceof Date) { if (!(second instanceof Date)) return false; return first === second; } else if (typeof first === 'string') { if (typeof second !== 'string') return false; return first === second; } else if (typeof first === 'number') { if (typeof second !== 'number') return false; return first === second; } if (Object.keys(first).length !== Object.keys(second).length) return false; for (let key in first) { if (!(key in second)) return false; if (!objectsAreEqual2(first[key], second[key])) return false; } return true; }
Tests:
json.stringify
objectsAreEqual1(obj1, obj2)
custom
objectsAreEqual2(obj1, obj2)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
json.stringify
custom
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):
I'll do my best to provide an answer based on the provided information. It appears that we have a JavaScript code snippet that contains a function `objectsAreEqual2` which is supposed to compare two objects for equality. The function seems to be designed to handle various types of data, including arrays, dates, numbers, strings, and objects. However, I notice that there's an issue with the `json.stringify` comparison in the first benchmark test case. Specifically, the `objectsAreEqual1` function uses `JSON.stringify(first) === JSON.stringify(second)`, which will not work correctly because it will also compare the string representations of the objects themselves, not just their values. To fix this, you could modify the `objectsAreEqual1` function to use a more robust comparison method, such as using a library like Lodash's `isEqual` function or implementing a custom equality check. Regarding the second test case, "custom", it seems that the benchmark is testing the performance of the `objectsAreEqual2` function. The latest benchmark result shows that Chrome 70 is executing this test at a rate of approximately 1879.4 executions per second. Overall, without more context or information about the specific requirements and constraints of the project, it's difficult to provide further guidance or suggestions for improvement. However, I hope this analysis helps to shed some light on the provided code snippet!
Related benchmarks:
test clone
Lodash cloneDeep vs JSON Clone (Large Object 2)
cloneJson Perf (reg json)
Test HOY
kakakakakaka123123x
Comments
Confirm delete:
Do you really want to delete benchmark?