ForLengthTest

JavaScript performance comparison

Revision 3 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var a = -0x76,
      b = 20,
      c = -18,
      d = '+22',
      e = false,
      f = null,
      g = [],
      h = '';
   
    function myMin() { //自己实现的Math.min
      switch (arguments.length) {
        case 0:
          return Infinity;
        case 1:
          return isNaN(Number(arguments[0])) ? Number(arguments[0]) : NaN;
        default:
          var res = arguments[0],
            tmp;
          for (var i = 0, l = arguments.length; i < l; i++) {
            tmp = arguments[i];
            if (typeof tmp !== "number") {
              tmp = Number(tmp);
              if (isNaN(tmp)) {
                return NaN;
              }
            }
            res = res < tmp ? res : tmp;
          }
          return res;
      }
    }
};
</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
test1
myMin(a, b, c, d, e, f, g, h);
pending…
test2
Math.min(a, b, c, d, e, f, g, h);
pending…
test3
 
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