LineCount

JavaScript performance comparison

Test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var s = "abc\ndef\nghi\njkl\nmn\nopq\nrst\nuvw\nxyz"

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
split
s.split("\n").length;
pending…
charAt
var lines = 1;
for (var i = 0, n = s.length; i < n; i++)
  if (s.charAt(i) == "\n")
    lines++;
pending…
indexOf
var lines = 1;
var i = -1;
while ((i = s.indexOf("\n", i + 1)) >= 0)
  lines++;
pending…

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

0 Comments