Lexing: char-iteration vs. slice

JavaScript performance comparison

Test case created

Preparation code

  var giantStr = (new Array(1000)).join('abcdef');

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;
var str = giantStr;
var x;
while (str.length !== 0) {
  x = str.substr(5);
  str = str.slice(5);

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

Compare results of other browsers


Comment form temporarily disabled.

Add a comment