Variant 1 (& power of 2): 0.58
Variant 2 (% size) : 6.56
Variant 3 (if, subtract): 1.25
Variant 4 (no if) : 1.44
Variant 1 (& power of 2): 0.58
Variant 2 (% size) : 6.56
Variant 3 (if, subtract): 1.25
Variant 4 (no if) : 1.44
Variant 1 (& power of 2): 15.92
Variant 2 (% size) : 18.92
Variant 3 (if, subtract): 17.48
Variant 4 (no if) : 16.76
Size = 1 billion
Variant 1 (& power of 2): 15.92
Variant 2 (% size) : 18.92
Variant 3 (if, subtract): 17.48
Variant 4 (no if) : 16.76
Size = 4 million
Variant 1 (& power of 2): 2.48
Variant 2 (% size) : 7.11
Variant 3 (if, subtract): 2.58
Variant 4 (no if) : 2.52
So it appears that at large sizes, the memory manipulation of the bit array will be the limiting factor and not the hash calculation. So you can choose from the above 4 variants based on: