Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
string.slice vs regex
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36
Browser:
Chrome 129
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
regex
431.6 Ops/sec
slice
1378.3 Ops/sec
array
1114.3 Ops/sec
Script Preparation code:
const strings = [ 'onclick', 'onwheel', 'onresize', 'noclick', 'nowheel', 'noresize' ]; function getStrings() { return strings; }
Tests:
regex
const regex = /^on/ for( let i = 0; i < 10000; i++ ) { getStrings().forEach( str => regex.test( str ) ); }
slice
for( let i = 0; i < 10000; i++ ) { getStrings().forEach( str => str.slice(0, 2) === 'on' ); }
array
for( let i = 0; i < 10000; i++ ) { getStrings().forEach( str => str[ 0 ] === 'o' && str[ 1 ] === 'n' ); }