Math.floor vs Math.round vs parseInt vs Bitwise (v85)

Revision 85 of this benchmark created by atSetKey on


Description

Rounding in all form possible

Test runner

Ready to run.

Testing in
TestOps/sec
Math.floor
for(var i=0;i<100000;i+=1){
Math.floor(89.938 / 293.3);
Math.floor(83784 / 9289.2);
Math.floor(7 / 60);
}
ready
Math.round
for(var i=0;i<100000;i+=1){
Math.round(89.938 / 293.3);
Math.round(83784 / 9289.2);
Math.round(7 / 60);
}
ready
parseInt
for(var i=0;i<100000;i+=1){
parseInt(89.938 / 293.3);
parseInt(83784 / 9289.2);
parseInt(7 / 60);
}
ready
Bitwise |
for(var i=0;i<100000;i+=1){
89.938 / 293.3 | 0;
83784 / 9289.2 | 0;
7 / 60 | 0;
}
ready
Bitwise >>
for(var i=0;i<100000;i+=1){
89.938 / 293.3 >> 0;
83784 / 9289.2 >> 0;
7 / 60 >> 0;
}
ready
Double negate
for(var i=0;i<100000;i+=1){
~~(89.938 / 293.3);
~~(83784 / 9289.2);
~~(7 / 60);
}
ready
Bitwise >>>
for(var i=0;i<100000;i+=1){
89.938 / 293.3 >>> 0;
83784 / 9289.2 >>> 0;
7 / 60 >>> 0;
}
ready
Bitwise <<
for(var i=0;i<100000;i+=1){
89.938 / 293.3 << 0;
83784 / 9289.2 << 0;
7 / 60 << 0;
}
ready
Math.ceil
for(var i=0;i<100000;i+=1){
Math.ceil(89.938 / 293.3);
Math.ceil(83784 / 9289.2);
Math.ceil(7 / 60);
}
ready

Revisions

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