psf / pyperf

Toolkit to run Python benchmarks
http://pyperf.readthedocs.io/
MIT License
799 stars 78 forks source link

Handling return from benchmarked functions #73

Closed adamjhc closed 4 years ago

adamjhc commented 4 years ago

Hi, is there any way to handle the output of a function while it is being benchmarked by runner.bench_func?

Something like:

benchmark, output = runner.bench_func("Test", func)

or

benchmark = runner.bench_func("Test", func)
output = benchmark.get_output()

I understand this assumes the function is deterministic but having the option would be nice.

Thanks!

vstinner commented 4 years ago

bench_func() calls the function many times. The result cannot be returned since it's an unknown number of results which are computed. If you want to get the result, call the function explicitly, no?

adamjhc commented 4 years ago

Somehow didn't think of this... this would work for relatively quick functions but would be a pain for slower ones.

Thanks