| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
@eendebakpt, something happened with the milestone. |
Sorry, something went wrong.
|
This PR is stale because it has been open for 30 days with no activity. |
Sorry, something went wrong.
# Conflicts: # Python/specialize.c
|
Updated benchmarks:
rshift_largeint is the negative control — the guard correctly rejects non-compact operands, so large-int code pays zero overhead. Benchmark script"""Microbenchmarks for compact-int shift specialization (gh-100239)."""
import pyperf
def bench_lshift_compactint(loops):
range_it = range(loops)
a = 3
t0 = pyperf.perf_counter()
for _ in range_it:
a << 1; a << 2; a << 3; a << 4; a << 5
a << 1; a << 2; a << 3; a << 4; a << 5
a << 1; a << 2; a << 3; a << 4; a << 5
a << 1; a << 2; a << 3; a << 4; a << 5
return pyperf.perf_counter() - t0
def bench_rshift_compactint(loops):
range_it = range(loops)
a = 1 << 20
t0 = pyperf.perf_counter()
for _ in range_it:
a >> 1; a >> 2; a >> 3; a >> 4; a >> 5
a >> 1; a >> 2; a >> 3; a >> 4; a >> 5
a >> 1; a >> 2; a >> 3; a >> 4; a >> 5
a >> 1; a >> 2; a >> 3; a >> 4; a >> 5
return pyperf.perf_counter() - t0
def bench_rshift_largeint(loops):
range_it = range(loops)
a = 1 << 200
t0 = pyperf.perf_counter()
for _ in range_it:
a >> 1; a >> 2; a >> 3; a >> 4; a >> 5
a >> 1; a >> 2; a >> 3; a >> 4; a >> 5
a >> 1; a >> 2; a >> 3; a >> 4; a >> 5
a >> 1; a >> 2; a >> 3; a >> 4; a >> 5
return pyperf.perf_counter() - t0
def bench_lshift_loop_var(loops):
range_it = range(loops)
t0 = pyperf.perf_counter()
for _ in range_it:
a = 5
for i in range(16):
a << i
return pyperf.perf_counter() - t0
def bench_rshift_loop_var(loops):
range_it = range(loops)
t0 = pyperf.perf_counter()
for _ in range_it:
a = 1 << 16
for i in range(16):
a >> i
return pyperf.perf_counter() - t0
def bench_inplace_lshift(loops):
range_it = range(loops)
t0 = pyperf.perf_counter()
for _ in range_it:
a = 1
a <<= 1; a >>= 1
a <<= 2; a >>= 2
a <<= 3; a >>= 3
a <<= 4; a >>= 4
a <<= 5; a >>= 5
return pyperf.perf_counter() - t0
if __name__ == "__main__":
runner = pyperf.Runner()
runner.bench_time_func("lshift_compactint", bench_lshift_compactint, inner_loops=20)
runner.bench_time_func("rshift_compactint", bench_rshift_compactint, inner_loops=20)
runner.bench_time_func("rshift_largeint", bench_rshift_largeint, inner_loops=20)
runner.bench_time_func("lshift_loop_var", bench_lshift_loop_var)
runner.bench_time_func("rshift_loop_var", bench_rshift_loop_var)
runner.bench_time_func("inplace_shift_mix", bench_inplace_lshift, inner_loops=10) |
Sorry, something went wrong.
Documentation build overview9 files changed · ± 9 modified ± Modified |
Sorry, something went wrong.
|
This PR is stale because it has been open for 90 days with no activity. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
We add a specialization for >> and >> on compact integers.
Benchmark:
(non-PGO, Windows)
There is a gain with the specialization, but on the other hand: how many shift operations on compact ints are there? For example the shifts are used in the uuid module, but always on large ints.