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; rv:131.0) Gecko/20100101 Firefox/131.0
Browser:
Firefox 131
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
regex
203.3 Ops/sec
slice
595.7 Ops/sec
array
947.8 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' ); }