and_vs_mod.py: extract 900 as SHIFT_VALUE_DIVIDER
`benchmarking/and_vs_mod.py`: Extract the value `900` as a constant `SHIFT_VALUE_DIVIDER`, make a independent constant `MAX_SHIFT_VALUE` based on it.
This commit is contained in:
parent
0f321d809d
commit
73b53b6f8f
|
@ -5,19 +5,21 @@ import random
|
|||
|
||||
BENCHMARK_COUNT = 180
|
||||
SUPERTESTS = 90
|
||||
MAX_SHIFT_VALUE = 18
|
||||
SHIFT_VALUE_DIVIDER = SUPERTESTS // MAX_SHIFT_VALUE
|
||||
|
||||
op_and = lambda a, b: a & (b - 1)
|
||||
op_mod = lambda a, b: a % b
|
||||
|
||||
timeit_macro = lambda func_name, number: timeit(
|
||||
f"%s(random.randint(0, 2 ** 32 - 1), 1 << ({number} // 900))" % func_name,
|
||||
f"%s(random.randint(0, 2 ** 32 - 1), 1 << ({number} // SHIFT_VALUE_DIVIDER))" % func_name,
|
||||
setup="from __main__ import %s\nimport random" % func_name,
|
||||
number=number,
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(
|
||||
f"Testing performance of modulo and bitwise AND remainder methods for binary divisors from 1 to {1 << (BENCHMARK_COUNT * (SUPERTESTS - 1) // 900)}:"
|
||||
f"Testing performance of modulo and bitwise AND remainder methods for binary divisors from 1 to {1 << (BENCHMARK_COUNT * (SUPERTESTS - 1) // SHIFT_VALUE_DIVIDER)}:"
|
||||
)
|
||||
|
||||
time1_total = 0
|
||||
|
|
Loading…
Reference in New Issue