charCodeAt vs charAt

JavaScript performance comparison

Revision 2 of this test case created by Jonas Fischer

Preparation code

<script>
  var a = 'A........................',
      b = 'Z........................',
      x, y;
</script>
    

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
charCodeAt and double equals
x = (a.charCodeAt(0) == 65);
y = (b.charCodeAt(0) == 65);
pending…
charCodeAt and triple equals
x = (a.charCodeAt(0) === 65);
y = (b.charCodeAt(0) === 65);
pending…
charAt and double equals
x = (a.charAt(0) == 'A');
y = (b.charAt(0) == 'A');
pending…
charAt and triple equals
x = (a.charAt(0) === 'A');
y = (b.charAt(0) === 'A');
pending…
pos and double equals
x = (a[0] == 'A');
y = (b[0] == 'A');
pending…
pos and triple equals
x = (a[0] === 'A');
y = (b[0] === 'A');
pending…

Compare results of other browsers

Revisions

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

0 Comments