GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-132509: Speed up bytes iteration in FOR_ITER_VIRTUAL by Wulian233 · Pull Request #157353 · python/cpython Conversation
|
| Benchmark | Main | PR | Throughput improvement |
|---|---|---|---|
| Empty loop | 13.858 ns/item | 11.850 ns/item | 16.9% faster |
| XOR accumulation | 28.195 ns/item | 25.409 ns/item | 11.0% faster |
| Conditional count | 28.649 ns/item | 24.721 ns/item | 15.9% faster |
import statistics import timeit DATA = bytes(range(256)) * 4096 # 1 MiB NUMBER = 10 REPEAT = 11 def loop_pass(): for byte in DATA: pass def loop_xor(): result = 0 for byte in DATA: result ^= byte return result def loop_count(): result = 0 for byte in DATA: if byte == 255: result += 1 return result BENCHMARKS = ( ("empty loop", loop_pass), ("xor accumulation", loop_xor), ("conditional count", loop_count), ) # Warm up adaptive specialization. for _, benchmark in BENCHMARKS: for _ in range(10): benchmark() print("| Benchmark | Median | Minimum | Median ns/item |") print("|---|---:|---:|---:|") for name, benchmark in BENCHMARKS: samples = timeit.repeat( benchmark, number=NUMBER, repeat=REPEAT, ) median = statistics.median(samples) minimum = min(samples) ns_per_item = median * 1e9 / (NUMBER * len(DATA)) print( f"| {name} | {median:.9f} s | " f"{minimum:.9f} s | {ns_per_item:.3f} |" )
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Py_ssize_t index = PyStackRef_UntagInt(null_or_index); | ||
| _PyObjectIndexPair next_index = Py_TYPE(iter_o)->_tp_iteritem(iter_o, index); | ||
| _PyObjectIndexPair next_index; | ||
| if (PyBytes_CheckExact(iter_o)) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Why special-case bytes here specifically? Doesn't seem related to the linked issue either.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.