You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
minor inefficency in the statistics module #154947
def test_a(ld, i, m):
n = 100
i_m = i * m
j = i_m // n # rescale i to m/n
j = 1 if j < 1 else ld-1 if j > ld-1 else j # clamp to 1 .. ld-1
delta = i_m - j*n
def test_b(ld, i, m):
n = 100
j = i * m // n # rescale i to m/n
j = 1 if j < 1 else ld-1 if j > ld-1 else j # clamp to 1 .. ld-1
delta = i * m - j*n
_ld = 234
_i = 3
_m = _ld + 1
x = timeit(lambda : test_a(_ld, _i, _m), number=10_000_000)
y = timeit(lambda : test_b(_ld, _i, _m), number=10_000_000)
This benchmark is neither correct nor relevant; I am closing this. Use pyperf for more robust checks and benchmark the entire function as well instead of just thjs arithmetic part. Timeit does not givr any information (and use PGO/LTO builds).
Activity
picnixz commentedon Jul 30, 2026
If you believe there is a real improvement this should be backed by benchmarks. I do not think this matters though.
lbaumbauer commentedon Jul 30, 2026
lol
`from timeit import timeit
a = 1.23456789
def test_a(ld, i, m):
n = 100
i_m = i * m
j = i_m // n # rescale i to m/n
j = 1 if j < 1 else ld-1 if j > ld-1 else j # clamp to 1 .. ld-1
delta = i_m - j*n
def test_b(ld, i, m):
n = 100
j = i * m // n # rescale i to m/n
j = 1 if j < 1 else ld-1 if j > ld-1 else j # clamp to 1 .. ld-1
delta = i * m - j*n
_ld = 234
_i = 3
_m = _ld + 1
x = timeit(lambda : test_a(_ld, _i, _m), number=10_000_000)
y = timeit(lambda : test_b(_ld, _i, _m), number=10_000_000)
print(f"{x / y}")
`
0.925picnixz commentedon Jul 31, 2026
This benchmark is neither correct nor relevant; I am closing this. Use pyperf for more robust checks and benchmark the entire function as well instead of just thjs arithmetic part. Timeit does not givr any information (and use PGO/LTO builds).