Math.ceil vs. bitwise (v6)

Revision 6 of this benchmark created by Adam Bankin on


Description

...and some extra logic to handle ints. ::sigh::

Setup

var n = Math.random() * 1e8,
        Utils = {
        bitwiseCeil: function(n) {
          var f = (n << 0);
          return f == n ? f : f + 1;
        },
        bitwiseCeil2: function(n) {
          var f = (n << 0);
          return f === n ? f : f + 1;
        }
        };
    
    function bitwiseCeil(n) {
      var f = (n << 0);
      return f == n ? f : f + 1;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Math.ceil
var f = Math.ceil(n);
ready
<<
var f = (n << 0);

f = (f == n)? f: f + 1;
ready
Bitwise In function
var f = bitwiseCeil(n);
ready
Bitwise in class [1]
var f = Utils.bitwiseCeil(n);
ready
Bitwise in class [2]
var f = Utils.bitwiseCeil2(n);
ready

Revisions

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