elm reverse

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
     function toArray(xs) {
              var out = [];
              while (xs[0] === "Cons") {
                out.push(xs[1]);
                xs = xs[2];
              }
              return out;
            }
           
              function fromArray(arr) {
                var out = ["Nil"];
                for (var i = arr.length; i--; ) {
                  out = ["Cons", arr[i], out];
                }
                return out;
              }
           
           
            function mkList(n) {
                  var out = ["Nil"];
                  for (var i = n; i--; ) {
                   out = ["Cons",i,out];
                  }
                  return out;
                }
               
                var list = mkList(1000);
   
      function foldl(f) { return function(b) { return function(xs) {
         var acc = b;
         while (xs[0] === "Cons") {
           acc = f(xs[1])(acc);
           xs = xs[2];
         }
         return acc;
        }
       }
      }
   
    function reverseA(xs) {
      return foldl(function(hd){return function(tl){return ["Cons",hd,tl];}})(["Nil"])(xs);
    }
   
    function reverseB(xs) {
      return fromArray(toArray(xs).reverse());
    }
};
</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
old
reverseA(list)
pending…
new
reverseB(list)
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment