räkna

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var s = "1234 anders 56789";
    var n = "25";
   
    function anders2(s, n) {
      n > 100 && (n = 100);
      n < 0 && (n = 0);
      var a = s.length,
        l = a * n / 100 + .5 | 0,
        c = (a - l) / 2 + .5 | 0;
      return s.match(new RegExp("(.){" + c + "}((.){" + l + "})"))[2];
    }
   
    function anders(s, n) {
      var a = s.length,
        l = a * (n / 100) + .5 | 0,
        c = (a - l) / 2 + .5 | 0;
      return s.match(new RegExp("(.){" + c + "}((.){" + l + "})"))[2];
    }
};
</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
a
anders(s, n)
pending…
j
anders2(s, n)
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