question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JSON parse JSON stringify speed test

See original GitHub issue

How does the speed of this compare to using JSON.parse(JSON.stringify(obj)) === JSON.parse(JSON.stringify(obj2))?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
SashaKorocommented, Dec 26, 2019

After looking into it, this comparison actually fits better in the fast-deep-equal repo. A JSON.stringify(obj1) === JSON.stringify(obj2) comparison cannot handle circular references and should never be used when data might contain React components. It’s also pretty slow when running generic data, as well as susceptible to giving false positives in many other cases.

--- speed tests: generic usage ---

react-fast-compare x 160,023 ops/sec ±0.88% (90 runs sampled)
fast-deep-equal x 158,356 ops/sec ±0.31% (94 runs sampled)
lodash.isEqual x 34,607 ops/sec ±0.52% (94 runs sampled)
nano-equal x 162,973 ops/sec ±0.38% (94 runs sampled)
shallow-equal-fuzzy x 135,792 ops/sec ±0.39% (92 runs sampled)
JSON.stringify x 23,047 ops/sec ±0.56% (94 runs sampled)
JSON.stringify
- different result: JSON.stringify scalars Infinity and -Infinity are not equal
- different result: JSON.stringify objects equal objects (different properties "order")
- different result: JSON.stringify objects object with extra undefined properties are not equal #1
- different result: JSON.stringify objects object with extra undefined properties are not equal #2
- different result: JSON.stringify objects object with extra undefined properties are not equal #3
- different result: JSON.stringify Date objects date and string are not equal
- different result: JSON.stringify RegExp objects not equal RegExp objects (different pattern)
- different result: JSON.stringify RegExp objects not equal RegExp objects (different flags)
- different result: JSON.stringify RegExp objects RegExp and object are not equal
- different result: JSON.stringify functions different functions are not equal
- different result: JSON.stringify sample objects big object
- error: React elements an element compared with itself Converting circular structure to JSON
- error: React elements two elements equal by value Converting circular structure to JSON
- error: React elements two elements unequal by value Converting circular structure to JSON
0reactions
chrisbolincommented, Dec 27, 2019

@SashaKoro agreed. And thanks for posting the results- that’s really interesting!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can JSON.parse() performance be improvement? - ITNEXT
const objD = JSON.parse(JSON.stringify(objA));. If you test how long it would take to copy 1⁰⁹ object using those methods you get results like...
Read more >
Performance of JSON Parse/Stringify - Stack Overflow
From my tests in Chrome JSON.stringify will be much faster than Array.join - but when parsing it, String.split seems to be faster.
Read more >
Benchmark: JSON Stringify Speed Test - MeasureThat.net
JSON Stringify Speed Test (version: 0). This benchmark tests whether the speed or JSON.stringify changes with object size. Comparing performance of: 1 vs...
Read more >
Why JSON.parse(JSON.stringify()) is a bad practice to clone ...
The JSON.stringify() just converts a JavaScript value to a JSON string. It`s ok to use it with some primitives like Numbers, Strings or...
Read more >
60fps Javascript while you stringify, parse, process, compress ...
TL;DR I've created async versions of JSON stringify and parse plus a whole ... performance is massively impacted by our perception of speed....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found