Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
JSON Stringify with Circular Reference Speed Test
(version: 0)
This benchmark tests whether the speed or JSON.stringify changes with object size
Comparing performance of:
1 vs 2
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
1
const a = {}; for (let i = 0; i < 100000; i++) { a[i] = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; } JSON.stringify(a);
2
const a = {}; for (let i = 0; i < 100000; i++) { a[i] = "123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; } a[0] = a; try { JSON.stringify(a); } catch (err) { }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
1
2
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
11 months ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Browser/OS:
Chrome 136 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
1
25.9 Ops/sec
2
156.9 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's dive into the world of JavaScript microbenchmarks. **What is being tested?** The provided benchmark tests two different approaches to creating circular references in objects, which are then passed to `JSON.stringify()`. The goal is to determine whether the speed of JSON stringification changes with object size. **Options compared:** There are two test cases: 1. **Test Case 1:** Creates a large object (`a`) with 100,000 properties, each initialized with a long string value. Then, it calls `JSON.stringify(a)`. 2. **Test Case 2:** Similar to Test Case 1, but creates a circular reference by setting one of the properties to point back to the original object (`a[0] = a`). This causes a JavaScript error, which is caught and ignored. **Pros and Cons of each approach:** **Test Case 1 (no circular reference):** * Pros: + Simulates a common use case where objects are created with many properties. + Easy to understand and reproduce. * Cons: + May not accurately represent the behavior of `JSON.stringify()` when dealing with circular references. **Test Case 2 (with circular reference):** * Pros: + Provides valuable insight into how `JSON.stringify()` handles circular references, which can lead to performance issues in some cases. + Can help identify potential security vulnerabilities. * Cons: + The test case is slightly more complex and may be harder to understand and reproduce. **Library usage:** There is no explicit library used in these benchmark definitions. However, it's worth noting that `JSON.stringify()` uses the built-in JSON object and its internal algorithms to serialize objects. **Special JS feature or syntax:** There are a few features being used here: * **For loop**: Used to create the large object (`a`) with 100,000 properties. * **Circular reference**: Implemented by setting one of the properties to point back to the original object (`a[0] = a`). This is not a standard JavaScript feature but rather a creative way to test `JSON.stringify()` behavior. **Other alternatives:** If you'd like to explore alternative approaches or variations on this benchmark, here are some ideas: * Test different data structures, such as arrays or objects with nested properties. * Use a larger range of object sizes (e.g., 100,000 to 1,000,000 properties). * Introduce additional complexity by using functions or other dynamic values in the object creation process. * Experiment with different `JSON.stringify()` options, such as the `replacer` and `space` parameters. Keep in mind that these variations will likely require adjustments to the benchmark definitions and may not be directly comparable to the original test cases.
Related benchmarks:
JSON Stringify Speed Test
JSON Stringify Speed Test vs joining array
JSON Stringify Speed Test2
JSON Stringify Speed Test3
Comments
Confirm delete:
Do you really want to delete benchmark?