BigInt, integers using 64 bits are now available with latest v8, hence NodeJS and Chrome browsers.
With good old JavaScript numbers, bitwise operators are only working on 32 bits.
Now with BigInts, bitwise operators work on 64 bits!
The aim of this microbenchmark is to assess the performances of the '>>' operators to divide an integer.
To run the bench:
yarn install
node bitwise-bench.js
Results using node v10.11.0 on a MBP 2017:
Number divide x 728,685,410 ops/sec ±1.34% (83 runs sampled)
BigInt divide x 22,162,527 ops/sec ±0.76% (92 runs sampled)
BigInt bitwise x 26,741,007 ops/sec ±0.40% (91 runs sampled)
Fastest is Number divide
Sadly bitwise operators are as slow with BigInt as with Number :(
Let me know if you thinnkk I made an obvious mistake. I am sure there is room for improvement. Feedbacks are welcome!
I added another test to check number bitwise too:
Number divide x 619,531,374 ops/sec ±1.02% (86 runs sampled)
BigInt divide x 10,780,787 ops/sec ±1.88% (81 runs sampled)
Number bitwise x 610,695,732 ops/sec ±1.12% (83 runs sampled)
BigInt bitwise x 13,353,902 ops/sec ±1.12% (84 runs sampled)
Fastest is Number divide,number bitwise