get the last character

JavaScript performance comparison

Test case created by lifesinger

Preparation code

<script>

function charAt(s) {
  return s.charAt(s.length - 1) === '#';
}

function regex(s) {
  return /#$/.test(s);
}

var POUND_END_RE = /#$/;
function regex_cache(s) {
  return POUND_END_RE.test(s);
}

</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
charAt
charAt('foobar');
charAt('http://www.regular-expressions.info/refadv.html');
charAt('https://a.alipayobjects.com/ar/alipay.auth.checkcode-1.1.js#');
 
pending…
regex
regex('foobar');
regex('http://www.regular-expressions.info/refadv.html');
regex('https://a.alipayobjects.com/ar/alipay.auth.checkcode-1.1.js#');
 
pending…
regex_cache
regex_cache('foobar');
regex_cache('http://www.regular-expressions.info/refadv.html');
regex_cache('https://a.alipayobjects.com/ar/alipay.auth.checkcode-1.1.js#');
 
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. Here’s a list of current revisions for this page:

2 comments

Qifeng Liu commented :

We wanna know why.

Online Schools commented :

Why its doing like that only.. does he has anything more then that???

Thanks!

Add a comment