Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
render html/text vs. regex
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:136.0) Gecko/20100101 Firefox/136.0
Browser:
Firefox 136
Operating system:
Linux
Device Platform:
Desktop
Date tested:
9 months ago
Test name
Executions per second
regex
921191.4 Ops/sec
parse
17037.5 Ops/sec
Script Preparation code:
const string = "foobar<a>Link1</a>foobar<a>Link2</a>foobar<a>Link3</a>foobar<a>Link4</a>foobar<a>Link5</a>"
Tests:
regex
string.replace(/<a>(.*?)<\/a>/g, (match, p1) => { return `<a href="/path/${p1.toLowerCase()}>${p1}</a>`; });
parse
const parser = new DOMParser(); const parsed = parser.parseFromString(string, 'text/html'); const parsedAnchors = parsed.querySelectorAll('a'); parsedAnchors.forEach((anchor) => { const content = anchor.innerHTML; anchor.setAttribute('href', `/path/${content.toLowerCase()}`); });