src.benchmark module¶
Benchmark implementation
- class src.benchmark.Benchmark(input_path: Path)¶
Bases:
objectRuns a benchmarks (memory, cpu) with (
python,Cython,Nuitka) oninput_pathfiles using the:benchmarkpytest fixture frompytest-benchmarkframework@profiledecorator frommemory-profiler.
For
memorybenchmark the required directory structure needs to be:module ├── sample_funcs.py # implementation ├── main.py # entrypoint ├── test_sample_funcs.py # test caseswhere in
main.pywe call any functions fromsample.funcs.py. This is needed because once we compile thesample_funcs.pywe aren’t able to use theprofiledecorator frommemory-profilerin that case,mem_benchfunction will decorate all the functions that they match theprof_func_namewith@profilefor example:def sum_of_squares_benchmark(): sum_of_squares() @profile def sum_of_squares_benchmark(): sum_of_squares()
For
cpubenchmark the required directory structure needs to be:module ├── sample_funcs.py # implementation ├── test_sample_funcs.py # test cases
NOTES
this way of memory profiling isn’t accurate (because we don’t profile the actual python functions), and neither we can do for compiled code with python profiling tools, but it could be an indicator.
The
test filesare needed to be able to execute the functions with the right arguments.
- static cpu_bench(input_path: Path, engine: str) None¶
decorate all the test functions from the
input_pathwith the@benchmark_wrapperdecorator.Finally, invoke pytest within.
- static mem_bench(input_path: Path, prof_func_name: str, engine: str) None¶
decorate all the function(s) from the
input_pathwhere their name match theprof_func_namepattern, with the@profiledecorator frommemory_profiler.Finally, invoke pytest within.
- start(bench_type: str, compilers: Sequence[CompilerWrapper], prof_func_name: str = 'benchmark') None¶
Start the benchmark.