substr or charAt or str[0]? (v7)

Revision 7 of this benchmark created by TonyQ on


Description

http://stackoverflow.com/questions/6579774/whats-the-difference-between-substr0-1-or-charat0

Preparation HTML

<script>
  a = "abcdefghijklmnopqrstuvwxyz";
  a.prototype.chatAt = function(num){
    return this.substr(num,1);
  };
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
substr(0,1)
a.substr(0,1);
ready
charAt(0)
a.charAt(0)
ready
substr(10,1)
a.substr(10,1);
ready
charAt(10)
a.charAt(10)
ready
str[0]
a[0]
ready
str[10]
a[10]
ready

Revisions

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