structuredClone vs JSON.stringify: I Timed Both on Node 22
On Node 22, JSON.parse(JSON.stringify()) cloned objects 1.6 to 1.75 times faster than structuredClone across three sizes structuredClone handles Dates, Maps and circular references that the JSON method silently breaks or drops I benchmarked 20000, 2000 and 200 clone operations at three object depths, same count each run The JSON method still loses functions and undefined, so the speed win comes…
The comparison of structuredClone and JSON.stringify deep cloning methods in Node 22 reveals that the JSON method significantly outperforms structuredClone. Across three object sizes ranging from small to large, structuredClone was 1.6 to 1.75 times slower than JSON.stringify. This speed advantage comes at the cost of losing certain data types, such as functions and undefined values, which JSON.stringify also handles.
The benchmark script tested the performance of both methods with varying object depths and sizes, ensuring accurate results by checking for equal output shapes and avoiding potential GC pauses or CPU throttling glitches. The consistent results across multiple runs and object sizes prove that this speed gap is real and not an artifact of the specific script execution.
The results indicate that the choice between the two methods should depend on the specific use case and the trade-offs one is willing to make between performance and data fidelity.
Rewritten by urgent.news; may contain errors — check the original.