Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
filter unsafe token
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Browser:
Chrome 124
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Deep Clone
43.6 Ops/sec
Iterate All keys
89.4 Ops/sec
Deep Clone, but not parse
74.2 Ops/sec
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), 10000)
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), 10000)
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), 10000)