diff options
author | Antoine Prouvost <AntoinePrv@users.noreply.github.com> | 2020-09-11 05:55:18 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-11 10:55:18 +0100 |
commit | 73d4d5e8d6d449fc8663765a42aa8aeeee844489 (patch) | |
tree | 55f32578a2b7ac1ef422aa2d33d73f7fef7e8e20 /bindings/python/google_benchmark/example.py | |
parent | df9e2948fa7bfca1ddf530ae2b23a518ed55fab1 (diff) | |
download | google-benchmark-73d4d5e8d6d449fc8663765a42aa8aeeee844489.tar.gz google-benchmark-73d4d5e8d6d449fc8663765a42aa8aeeee844489.zip |
Bind benchmark builder to Python (#1040)v1.5.2
* Fix setup.py and reformat
* Bind benchmark
* Add benchmark option to Python
* Add Python examples for range, complexity, and thread
* Remove invalid multithreading in Python
* Bump Python bindings version to 0.2.0
Co-authored-by: Dominic Hamon <dominichamon@users.noreply.github.com>
Diffstat (limited to 'bindings/python/google_benchmark/example.py')
-rw-r--r-- | bindings/python/google_benchmark/example.py | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/bindings/python/google_benchmark/example.py b/bindings/python/google_benchmark/example.py index 9bb23c4..9134e8c 100644 --- a/bindings/python/google_benchmark/example.py +++ b/bindings/python/google_benchmark/example.py @@ -64,7 +64,7 @@ def manual_timing(state): while state: # Manually count Python CPU time start = time.perf_counter() # perf_counter_ns() in Python 3.7+ - # Somehting to benchmark + # Something to benchmark time.sleep(0.01) end = time.perf_counter() state.set_iteration_time(end - start) @@ -92,5 +92,45 @@ def custom_counters(state): state.counters["foo_avg_rate"] = Counter(num_foo, Counter.kAvgThreadsRate) +@benchmark.register +@benchmark.option.measure_process_cpu_time() +@benchmark.option.use_real_time() +def with_options(state): + while state: + sum(range(1_000_000)) + + +@benchmark.register(name="sum_million_microseconds") +@benchmark.option.unit(benchmark.kMicrosecond) +def with_options(state): + while state: + sum(range(1_000_000)) + + +@benchmark.register +@benchmark.option.arg(100) +@benchmark.option.arg(1000) +def passing_argument(state): + while state: + sum(range(state.range(0))) + + +@benchmark.register +@benchmark.option.range(8, limit=8 << 10) +def using_range(state): + while state: + sum(range(state.range(0))) + + +@benchmark.register +@benchmark.option.range_multiplier(2) +@benchmark.option.range(1 << 10, 1 << 18) +@benchmark.option.complexity(benchmark.oN) +def computing_complexity(state): + while state: + sum(range(state.range(0))) + state.complexity_n = state.range(0) + + if __name__ == "__main__": benchmark.main() |