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 (Macintosh; Intel Mac OS X 10.15; rv:134.0) Gecko/20100101 Firefox/134.0
Browser:
Firefox 134
Operating system:
Mac OS X 10.15
Device Platform:
Desktop
Date tested:
one year ago
regex with no lookbehind
3.4M/s
simple regex
3.3M/s
split + filter + join
2.6M/s
View exact numbers
Test name
Executions per second
✓
regex with no lookbehind
3,356,465 Ops/sec
simple regex
3,304,706 Ops/sec
split + filter + join
2,637,391 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("/");