Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
char index vs charAt() vs slice() vs startsWith() vs RegExp (FIXED)
Compare methods for testing string's beggining character.
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/121.0.0.0 Safari/537.36
Browser:
Chrome 121
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Benchmark engine:
Benchmark.js
startsWith()
15.3M/s
slice()
15.3M/s
charAt()
15.3M/s
character index
15.2M/s
RegExp
12.6M/s
View exact numbers
Test name
Executions per second
✓
startsWith()
15,320,079 Ops/sec
slice()
15,289,878 Ops/sec
charAt()
15,272,254 Ops/sec
character index
15,230,623 Ops/sec
RegExp
12,558,911 Ops/sec
Script Preparation code:
var str = '!foo bar baz'; var noop = Function.prototype;
Tests:
character index
if (str[0] === '!') noop();
charAt()
if (str.charAt(0) === '!') noop();
startsWith()
if (str.startsWith('!')) noop();
slice()
if (str.slice(0, 1) === '!') noop();
RegExp
if (/^!/.test(str)) noop();