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 (X11; Ubuntu; Linux x86_64; rv:129.0) Gecko/20100101 Firefox/129.0
Browser:
Firefox 129
Operating system:
Ubuntu
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
regex
929.2 Ops/sec
slice
2323.1 Ops/sec
array
2401.9 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' ); }