Math.floor vs Number.floor

JavaScript performance comparison

Revision 3 of this test case created by

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  Number.prototype.floor = function() {
  	return Math.floor(this);
  };
  
  Number.prototype.floor2 = function() {
    return ~~(this)
  };
  
  var x1 = 12.4;
  var x2 = 345.2;

};
</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
Math.floor
Math.floor(x1);
Math.floor(x2);
pending…
Number.floor
x1.floor();
x2.floor();
pending…
~~
~~(x1);
~~(x2);
pending…
Number.floor2
x1.floor2();
x2.floor2();
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.

0 Comments