Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
filter unsafe token 10w
(version: 0)
Comparing performance of:
Deep Clone vs Iterate All keys vs Deep Clone, but not parse
Created:
one year ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var params = Array.from({length: 30}).reduce((p, n, i) => { p['key' + i] = 'value' + i; return p; }, {}); function runTest(fn, cnt) { while(cnt--) {fn();} }
Tests:
Deep Clone
function fixParams(params) { const token = 'xxxxxxxxxxxxxxxxxxxx'; if (typeof params === 'object' && token) { try { const reg = new RegExp(token, 'g'); const str = JSON.stringify(params); str.replace(reg, 'yyyyyyyyyyyyy'); params = JSON.parse(str); } catch (e) { console.log(e); } } return params; } runTest(() => fixParams(params), 100000)
Iterate All keys
function deepReplace(params, regex, replacement) { for (let key in params) { if (typeof params[key] === 'object') { deepReplace(params[key], regex, replacement); } else if (regex.test(params[key])) { params[key] = params[key].replace(regex, replacement); } } } function fixParams(params) { const token = 'xxxxxxxxxxxxxxxxxxxx'; if (typeof params === 'object' && token) { try { const reg = new RegExp(token, 'g'); params = deepReplace(params, reg, 'yyyyyyyyyyyyy'); } catch (e) { console.log(e); } } return params; } runTest(() => fixParams(params), 100000)
Deep Clone, but not parse
function fixParams(params) { const token = 'xxxxxxxxxxxxxxxxxxxx'; if (typeof params === 'object' && token) { try { const reg = new RegExp(token, 'g'); const str = JSON.stringify(params); if (reg.test(str)) { str.replace(reg, 'yyyyyyyyyyyyy'); params = JSON.parse(str); } } catch (e) { console.log(e); } } return params; } runTest(() => fixParams(params), 100000)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Deep Clone
Iterate All keys
Deep Clone, but not parse
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5 Mobile/15E148 Safari/604.1
Browser/OS:
Mobile Safari 16 on iOS 16.5
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Deep Clone
4.7 Ops/sec
Iterate All keys
21.9 Ops/sec
Deep Clone, but not parse
16.9 Ops/sec
Related benchmarks:
Lodash vs Native reduce on object
Lodash vs Native reduce on object - updated 2
Lodash vs Native reduce on object x100
JS Filter vs Reduce vs Foreach
reduce vs filter 22
Comments
Confirm delete:
Do you really want to delete benchmark?