by binarymax · 2y ago · 0 comments
Instead of saying we should search for benchmarks why not post them here? Also, what is the small function you use?
I just did a test again with 40000 times cloning a simple object and JSON.parse/stringify was 6 times faster than structured cloning.
Since I heavily use deep cloning, I am still disappointed with the new native, but slower solution. (And was hoping there would be more than old news in the article)
Edit: Code for testing was as simple as
for ... 40000
JSON.parse(JSON.stringify(obj))
vs
structuredClone(obj)
Depending on the object you're cloning, that might be fine. But some types, like Date or Set, don't round trip between JS and JSON so you'd have mangled objects.