Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
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
Benchmark engine:
Benchmark.js
Regex.exec
27K/s
String.split (one-liner, mutation)
24K/s
String.split
23K/s
View exact numbers
Test name
Executions per second
✓
Regex.exec
26,575 Ops/sec
String.split (one-liner, mutation)
23,581 Ops/sec
String.split
23,270 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]; }