readline "split vs indexOf"

JavaScript performance comparison

Test case created by nanofi

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var text = ""
    for (var i = 0; i < 10000; i++) {
      text += "test" + i + "\n";
    }
};
</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
split
var a = []
var result = text.split("\n");
for(var i = 0, length = result.length; i < length; i++){
  a.push(result[i]);
}
pending…
indexOf
var a = [];
for (var i = 0, length = text.length; i < length;) {
  var last = text.indexOf("\n", i);
  var line = text.slice(i, last);
  a.push(line);
  i = last + 1;
}
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