Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Get file extension (String v.s. Regex)
Get file extension from path and name
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser:
Chrome 120
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
String.split
23269.8 Ops/sec
String.split (one-liner, mutation)
23581.4 Ops/sec
Regex.exec
26574.6 Ops/sec
Script Preparation code:
// There are 100 more files var filePaths = new Array(250).fill('').map(() => (crypto.randomUUID() + crypto.randomUUID()) .slice(0, 32) .replace(/c/g, '.') .replace(/(0|9|a)/g, '/'), ); var fileExt;
Tests:
String.split
for (const path of filePaths) { const args = path.split('.'); fileExt = args[args.length - 1]; }
String.split (one-liner, mutation)
for (const path of filePaths) { fileExt = path.split('.').pop(); }
Regex.exec
for (const path of filePaths) { fileExt = /\.([^\.]+)$/.exec(path)?.[1]; }