Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Trim leading and trailing slash (regex vs split filter)
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:
one year ago
simple regex
1.3M/s
regex with no lookbehind
1.3M/s
split + filter + join
790K/s
View exact numbers
Test name
Executions per second
✓
simple regex
1,338,792 Ops/sec
regex with no lookbehind
1,309,667 Ops/sec
split + filter + join
789,674 Ops/sec
Script Preparation code:
var s = '//the//////quick/brown///////////fox/jumps/over//the/lazy/dog////';
Tests:
simple regex
s.replace(/\/{2,}/g, "/").replace(/(^\/+|\/+$)/g, "");
regex with no lookbehind
s.replace(/\/{2,}/g, "/").replace(/(^\/+|(?<!\/)\/+$)/g, "");
split + filter + join
s.split("/").filter(Boolean).join("/");