Match first string character

Benchmark created on


Setup

const strs = [...new Array(15).keys()].map(_=>[
  '',
  '*',
  '#',
  '*short',
  '#short',
  '*'.padEnd(2500, '-'),
  '#'.padEnd(2500, '-'),
]).flat()

const re = /^\*/

Test runner

Ready to run.

Testing in
TestOps/sec
Regex 1
strs.filter(str => re.exec(str))
ready
startsWith
strs.filter(str => str.startsWith('*'))
ready
charAt
strs.filter(str => str.charAt(0) === '*')
ready
Index
strs.filter(str => str[0] === '*')
ready
Regex 2
strs.filter(str => str.match(re))
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.