Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
regex replace performance : chaining replace vs table function replace
(version: 1)
Comparing performance of:
chain vs table
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
const HTMLRegex = /[&<>"'`]/g; const HTMLTable = { "&": "&", "<": "<", ">": ">", '"': """, "'": "'", "`": "`", }; function sanitizeTable(text) { return text.replace(HTMLRegex, (match) => HTMLTable[match]); }; function sanitizeChain(text) { return text .replace(/&/g, "&") .replace(/</g, "<") .replace(/>/g, ">") .replace(/"/g, """) .replace(/'/g, "'") .replace(/`/g, "`"); }
Tests:
chain
sanitizeChain(`<div attr="'value&'"></div>`);
table
sanitizeTable(`<div attr="'value&'"></div>`);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
chain
table
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Browser/OS:
Chrome 130 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
chain
1644457.1 Ops/sec
table
2631762.8 Ops/sec
Related benchmarks:
string replaceAll test
replace vs substring vs slice from beginning (+ brackets, substr, compiled vs inline regex) rulez
rest params vs arguments (rest params are fast)
sa sad test
replaceAll vs regex replace for a newLine using html tags
String matching - Regex stripping vs Concatenation of strings
regex vs filter
regex vs filter 2
Regexp test for finding invalid character
Comments
Confirm delete:
Do you really want to delete benchmark?