charAt() vs startsWith() (v2)

Revision 2 of this benchmark created by Ryan Grove on


Setup

if (typeof String.prototype.startsWith !== 'function') {
    throw new Error('This browser does not support startsWith()');
  }
  
  var string = 'abcdefghijklmnopqrstuvwxyz';
  var result = null;

Test runner

Ready to run.

Testing in
TestOps/sec
charAt() - positive result
result = string.charAt(0) === 'a';
ready
charAt() - negative result
result = string.charAt(0) === 'z';
ready
startsWith() - positive result
result = string.startsWith('a');
ready
startsWith() - negative result
result = string.startsWith('z');
ready

Revisions

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

  • Revision 2: published by Ryan Grove on