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
Test name
Executions per second
simple regex
1338792.5 Ops/sec
regex with no lookbehind
1309667.4 Ops/sec
split + filter + join
789674.4 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("/");