Math.floor/ceil/round vs ~~

Benchmark created by Jacob DeHart on


Test runner

Ready to run.

Testing in
TestOps/sec
Math.floor()
a = Math.floor(123.456);
ready
~~ floor
a = ~~123.456; // ~ floor
ready
| 0 floor
a = 123.456 | 0;
ready
<< 0 floor
a = 123.456 << 0;
ready
Math.round
a = Math.round(123.456);
ready
~~ round
a = ~~(123.456+.5); // ~ round
ready
| 0 round
a = 123.456 + 0.5 | 0
ready
<< round
a = 123.456 + 0.5 << 0
ready
Math.ceil
a = Math.ceil(123.456);
ready
~~ ceil (high precision)
a = ~~(123.456 + 1-1e-100); // ~ ceil... high precision
ready
~~ ceil (low precision)
a = ~~(123.456 + 1-1e-10); // ~ ceil... low precision
ready
| 0 ceil (high precision)
a = (123.456 + 1-1e-100) | 0; // | 0 ceil... high precision
ready
| 0 ceil (low precision)
a = (123.456 + 1-1e-10) | 0; // | 0 ceil... high precision
ready
<< 0 ceil (high precision)
a = (123.456 + 1-1e-100) << 0;
ready
<<0 ceil (low precision)
a = (123.456 + 1-1e-10) << 0;
ready

Revisions

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

  • Revision 1: published by Jacob DeHart on