Detecting secure server: indexOf vs substr vs charAt (v3)

Revision 3 of this benchmark created on


Preparation HTML

<script>
  var a = 'https://secure.wikimedia.org',
      b = 'http://en.wikipedia.org',
      c, d;
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
indexOf('https://') === 0
c = a.indexOf('https://') === 0;
d = b.indexOf('https://') === 0;
ready
indexOf('https://') == 0
c = a.indexOf('https://') == 0;
d = b.indexOf('https://') == 0;
ready
substr(0, 8) === 'https://'
c = a.substr(0, 8) === 'https://';
d = b.substr(0, 8) === 'https://';
ready
substr(0, 8) == 'https://'
c = a.substr(0, 8) == 'https://';
d = b.substr(0, 8) == 'https://';
ready
.charAt(4) == 's'
c = a.charAt(4) == 's';
d = b.charAt(4) == 's';
ready
.charAt(4) === 's'
c = a.charAt(4) === 's';
d = b.charAt(4) === 's';
ready
.substring(4,5) == 's'
c = a.substring(4, 5) == 's';
d = b.substring(4, 5) == 's';
ready

Revisions

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