Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Fast & frequent comparisons
(version: 0)
Comparing performance of:
JSON.stringify vs H
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
Script Preparation code:
window.foo = [{accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'merp', ancestors: ['blah', 'merp']}, {accessPath: 'derp', ancestors: ['blah', 'derp']}]; window.foo = [{accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'derp.merp', ancestors: ['blah', 'blah']}, {accessPath: 'merp', ancestors: ['blah', 'merp']}, {accessPath: 'derp', ancestors: ['blah', 'changed']}]; async function H(m) { const msgUint8 = new TextEncoder().encode(m) const hashBuffer = await crypto.subtle.digest('SHA-1', msgUint8) const hashArray = Array.from(new Uint8Array(hashBuffer)) const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('') return hashHex; } async function compare(a, b) { return await H(a) === await H(b); }
Tests:
JSON.stringify
JSON.stringify(window.foo) === JSON.stringify(window.bar);
H
compare(window.foo, window.bar)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
JSON.stringify
H
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 dive into the world of MeasureThat.net and explore what's being tested in this benchmark. **Benchmark Definition** The benchmark is defined by two individual test cases: 1. `JSON.stringify(window.foo) === JSON.stringify(window.bar);` 2. `compare(window.foo, window.bar)` These test cases are designed to compare the contents of two objects using different approaches. **Test Case 1: `JSON.stringify`** This test case compares the results of calling `JSON.stringify()` on two different objects, `window.foo` and `window.bar`. The comparison is done by checking if the resulting strings from both `JSON.stringify()` calls are equal. **Pros and Cons** Using `JSON.stringify()` for comparison has its pros and cons: Pros: * Simple and straightforward * Works well for most cases Cons: * Can be slow for large objects, as it recursively traverses the object graph and converts each property to a string. * May not work correctly with certain types of objects or data structures. **Test Case 2: `compare` function** This test case uses a custom `compare` function that takes two objects as input and returns a boolean indicating whether they are equal. The comparison is done by hashing the contents of both objects using the SHA-1 algorithm and then comparing the resulting hash values. Pros: * Can be faster than `JSON.stringify()` for large objects, as it avoids the overhead of converting each property to a string. * May work correctly with certain types of objects or data structures that can't be compared using `JSON.stringify()` Cons: * Requires additional libraries and dependencies (e.g., Web Cryptography API) to implement the hashing algorithm. * Can be more complex to understand and maintain, especially for those without experience with hash functions. **Library: Lodash** The benchmark includes a reference to the Lodash library, which is used in the `Html Preparation Code` section. Specifically, the line `<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>` imports the `lodash` module, which provides various utility functions, including `stringify()`. **Special JS Feature/Syntax** There is no special JavaScript feature or syntax used in this benchmark that would require a deep understanding of advanced concepts like decorators, async/await, or ES6+ features. The code is relatively straightforward and focuses on demonstrating the comparison of two objects using different approaches. **Other Alternatives** Some alternative approaches to comparing objects could include: * Using a dedicated object comparison library (e.g., `ObjectComparer`). * Implementing a custom comparison function that uses a different algorithm or data structure. * Using a testing framework like Jest or Mocha, which provides built-in support for comparing objects. However, these alternatives would likely require additional setup and configuration, and may not be as straightforward to understand and maintain as the `JSON.stringify()` and `compare` approaches used in this benchmark.
Related benchmarks:
Lodash isEqual test333wer
jeffreytest
Lodash isEqual test fffw
Lodash isEqual vs stringify vs id compare test
Lodash vs. direct comparison
Comments
Confirm delete:
Do you really want to delete benchmark?