Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
JSON.stringify vs recursive for-loop
(version: 1)
Comparing performance of:
JSON.stringify vs recursive for-loop
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
const tree = [{ 'title': "some title", 'channel_id': '123we', 'options': [{ 'channel_id': 'abc', 'image': 'http://asdasd.com/all-inclusive-block-img.jpg', 'title': 'All-Inclusive', 'options': [{ 'channel_id': 'dsa2', 'title': 'Some Recommends', 'options': [{ 'image': 'http://www.asdasd.com', 'title': 'Sandals', 'id': '1', 'content': {} }] }] }] }, { 'title': "some title", 'channel_id': '123we', 'options': [{ 'channel_id': 'abc', 'image': 'http://asdasd.com/all-inclusive-block-img.jpg', 'title': 'All-Inclusive', 'options': [{ 'channel_id': 'dsa2', 'title': 'Some Recommends', 'options': [{ 'image': 'http://www.asdasd.com', 'title': 'Sandals', 'id': '2', 'content': {} }] }] }] } ];
Tests:
JSON.stringify
function findNestedObj(root, ID) { let item; JSON.stringify(root, (_, obj) => { if (obj && obj.id === ID) { item = obj; } return obj; }); return item; }; const result = findNestedObj(tree, '2');
recursive for-loop
function findNestedObj(root, ID) { let item; for (let i = 0; i < root.length && !item; i += 1) { if (root[i].id === ID) { item = root[i]; return item; } if (root[i].options) { item = findNestedObj(root[i].options, ID); if (item) return item; } } return item; }; const result = findNestedObj(tree, '2');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
JSON.stringify
recursive for-loop
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
4 months ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.127 Safari/537.36 OPR/60.3.3004.55692
Browser/OS:
Opera 60 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
JSON.stringify
11743.3 Ops/sec
recursive for-loop
292507.8 Ops/sec
Related benchmarks:
Lodash cloneDeep vs JSON Clone
Lodash vs JSON vs Ramda Clone vs old school ugly with moar json
Lodash vs JSON vs Ramda Clone vs fixed old school ugly with moar json
Lodash vs JSON vs Ramda vs the dirty
JSON.parse vs eval
cloneJson Perf (reg json)
Lodash deep clone vs JSON.stringfy davide
Lodash.isEqual vs JSON.stringify big object
JSON.stringify vs Text (huge json dummy)
Comments
Confirm delete:
Do you really want to delete benchmark?