Lexing: char-iteration vs. slice

JavaScript performance comparison

Test case created

Preparation code

<script>
  var giantStr = (new Array(1000)).join('abcdef');
</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
Char iteration
var c, a, len;
for (a = 0, len = giantStr.length; a < len; a++) {
  c = giantStr[a];
  c = c + 1; // do something minor with c;
}
pending…
Slicing
var str = giantStr;
var x;
while (str.length !== 0) {
  x = str.substr(5);
  str = str.slice(5);
}
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