Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
En-To-Em Dash Regex
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36
Browser:
Chrome 118
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Option 1 (Lookarounds)
549139.9 Ops/sec
Option 2 (Clever)
486343.4 Ops/sec
Option 3 (Capture Groups)
692102.8 Ops/sec
Option 4 (Two-Pass)
378525.8 Ops/sec
Option 5 (Normal)
224293.7 Ops/sec
Script Preparation code:
const testString = "This – is – a –test –string – with – multiple – instances– of–the – pattern – and – some – variations – like–this –and this– "; const regex1 = /(?<= )–(?= )|(?<! )– (?! )| –(?<! ) ?/g; const regex2 = / (?=–)–? ?|– /g; const regex3 = /(?<= )–(?! )|–(?= )|(?<! )– (?! )/g; const regex4step1 = / +– +/g; // Remove cases with spaces on both sides const regex4step2 = / +–|– +/g; // Remove extra spaces const regex5 = / – | –|– /g; const regex6 = / – ?|– /g;
Tests:
Option 1 (Lookarounds)
testString.replace(regex1, "—");
Option 2 (Simple Lookaround)
testString.replace(regex2, "—");
Option 3 (Clever)
testString.replace(regex3, "$1—");
Option 4 (Two-Pass)
testString.replace(regex4step1, " – ").replace(regex4step2, "—");
Option 5 (Normal)
testString.replace(regex5, "—");
Option 6 (I Am Dumb)
testString.replace(regex6, "—");