Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
slice vs regex
foo
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64; rv:152.0) Gecko/20100101 Firefox/152.0
Browser:
Firefox 152
Operating system:
Linux
Device Platform:
Desktop
Date tested:
7 days ago
brackets
1412.8M/s
slice
1383.1M/s
regex
17.9M/s
View exact numbers
Test name
Executions per second
✓
brackets
1,412,826,240 Ops/sec
slice
1,383,141,888 Ops/sec
regex
17,900,016 Ops/sec
Script Preparation code:
var strIn = '1234-12-34 05:27:56Z'; var strOut = ''; var regex = /\d{4}-(\d{2})-(\d{2}) (\d{2})/;
Tests:
slice
var month = strIn.slice(5, 7); var day = strIn.slice(8, 10); var hour = strIn.slice(11, 13);
regex
var [_, month, day, hour] = strIn.match(regex)
brackets
var month = strIn[5] + strIn[6]; var day = strIn[8] + strIn[9]; var hour = strIn[11] + strIn[12];