Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Stringify with functions
(version: 5)
Comparing performance of:
stringify deep equality vs lodash isEqual deep equality
Created:
6 years ago
by:
Registered User
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>
Tests:
stringify deep equality
const testObject = {gameName: 'lotto', maxPrimaryLineLength: 6, maxSecondaryLineLength: 0,currentPrimaryLine: [1,2,3,4,5],currentSecondaryLine: [], func: () => {console.log('test'); if (true) console.log('test2')} , gameName2: 'lotto', maxPrimaryLineLength2: 6, maxSecondaryLineLength2: 0,currentPrimaryLine2: [1,2,3,4,5],currentSecondaryLine2: [], func2: () => {console.log('test'); if (true) console.log('test2')}} const testObject2 = {gameName: 'lotto', maxPrimaryLineLength: 6, maxSecondaryLineLength: 0,currentPrimaryLine: [1,2,3,4,5],currentSecondaryLine: [], func: () => {console.log('test'); if (true) console.log('test2')} , gameName2: 'lotto', maxPrimaryLineLength2: 6, maxSecondaryLineLength2: 0,currentPrimaryLine2: [1,2,3,4,5],currentSecondaryLine2: [], func2: () => {console.log('test'); if (true) console.log('test2')}} console.log(JSON.stringify(testObject) === JSON.stringify(testObject2));
lodash isEqual deep equality
const testObject = {gameName: 'lotto', maxPrimaryLineLength: 6, maxSecondaryLineLength: 0,currentPrimaryLine: [1,2,3,4,5],currentSecondaryLine: [], func: () => {console.log('test'); if (true) console.log('test2')} , gameName2: 'lotto', maxPrimaryLineLength2: 6, maxSecondaryLineLength2: 0,currentPrimaryLine2: [1,2,3,4,5],currentSecondaryLine2: [], func2: () => {console.log('test'); if (true) console.log('test2')}} const testObject2 = {gameName: 'lotto', maxPrimaryLineLength: 6, maxSecondaryLineLength: 0,currentPrimaryLine: [1,2,3,4,5],currentSecondaryLine: [], func: () => {console.log('test'); if (true) console.log('test2')} , gameName2: 'lotto', maxPrimaryLineLength2: 6, maxSecondaryLineLength2: 0,currentPrimaryLine2: [1,2,3,4,5],currentSecondaryLine2: [], func2: () => {console.log('test'); if (true) console.log('test2')}} console.log(_.isEqual(testObject,testObject2));
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
stringify deep equality
lodash isEqual deep equality
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):
Let's break down the provided benchmark and explain what's being tested. **Overall Purpose:** The benchmark measures the performance of two different approaches to compare the equality of objects in JavaScript. **Options Compared:** 1. **Stringifying with functions**: This approach involves converting the objects to strings using the `JSON.stringify()` method, and then comparing these strings for equality. 2. **Using a library (Lodash)**: Specifically, the benchmark uses the `_.isEqual()` function from Lodash to compare the equality of two objects. **Pros and Cons of Each Approach:** 1. **Stringifying with functions:** * Pros: + Simple to implement + Doesn't require an external library * Cons: + May not work correctly for complex object structures or nested arrays + Can be slower than using a specialized library like Lodash 2. **Using a library (Lodash):** * Pros: + Fast and efficient + Handles complex object structures and nested arrays correctly * Cons: + Requires an external library to be included in the test **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for working with data, including equality checks. The `_.isEqual()` function used in this benchmark compares two objects or arrays for deep equality, which means it checks not only the values but also the structure and nested properties. **Special JS Feature/Syntax:** The benchmark uses JavaScript's template literals feature to create complex object literals. These literals allow you to embed expressions inside string literals using the `$` symbol, making it easier to create complex data structures. **Other Considerations:** * The benchmark uses a simulated user agent (UAP) string and device platform to mimic real-world usage scenarios. * The `ExecutionsPerSecond` value indicates how many times each test is executed per second, which can affect the accuracy of the results. **Alternatives:** If you want to measure the performance of other approaches for comparing object equality in JavaScript, you could consider using: 1. **JSON.parse(JSON.stringify(obj))**: This approach involves converting an object to a JSON string and then parsing it back into an object. 2. **Using a custom equality function**: You can create your own custom function to compare two objects or arrays for equality. However, keep in mind that these alternatives may have different trade-offs in terms of performance, simplicity, and accuracy compared to the approaches used in this benchmark.
Related benchmarks:
isFunction vs typeof function 6
isEmpty vs. vanilla
Lodash isString
topkek
Lodash isString fork
Comments
Confirm delete:
Do you really want to delete benchmark?