string split vs textcodeat

JavaScript performance comparison

Test case created by spaznode

Preparation code

<script>
var input = ["40.01 - 45", "5.01 - 10", "50.01 - 55", "60.01 - 65", "60.01 - 65", "60.01 - 65", "60.01 - 65", "40.01 - 45", "5.01 - 10", "50.01 - 55", "60.01 - 65", "60.01 - 65", "60.01 - 65", "60.01 - 65", "40.01 - 45", "5.01 - 10", "50.01 - 55", "60.01 - 65", "60.01 - 65", "60.01 - 65", "60.01 - 65", "40.01 - 45", "5.01 - 10", "50.01 - 55", "60.01 - 65", "60.01 - 65", "60.01 - 65", "60.01 - 65", "40.01 - 45", "5.01 - 10", "50.01 - 55", "60.01 - 65", "60.01 - 65", "60.01 - 65", "60.01 - 65"]

function parseSplit(str) {
  return str.split("-")
}

var charAtDelim = "-".charCodeAt(0)

function parseCharAt(str) {
 var N = str.length,
I = 0

      while (I < N) {
        var c = str.charCodeAt(I++)
       if (c !== charAtDelim) continue;
        return [str.substring(0, I), str.substring(I + 1)];
      }
}
</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
parseSplit
input.forEach(function(f){
parseSplit(f)
})
pending…
charCodeAt
input.forEach(function(f){
parseCharAt(f)
})
pending…

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

Compare results of other browsers

0 comments

Add a comment