Crates.io | energy-bench |
lib.rs | energy-bench |
version | 0.1.1 |
source | src |
created_at | 2024-05-06 08:38:28.868456 |
updated_at | 2024-05-06 09:04:21.633203 |
description | Methods for benchmarking the energy consumption of programs. |
homepage | |
repository | https://gitlab.com/software-energy-lab/energy-benchmarking |
max_upload_size | |
id | 1230986 |
size | 44,937 |
Tool for benchmarking the energy consumption of programs.
A new benchmark builder can be created with EnergyTool::new
.
If you require an additional function for generating data, use EnergyTool::from_data
.
Time and energy consumption of data generation are not included in the results.
use energy_bench::EnergyTool;
let json = EnergyTool::new(the_function).benchmark()?;
let json = EnergyTool::from_data(sort, uniform).benchmark()?;
The benchmark can easily be repeated multiple times:
let builder = EnergyTool::from_default(the_function)
.with_number_of_measurements(5)
And results can directly be written to a file:
let file = &File::create("the_file.json")?;
let builder = EnergyTool::from_default(the_function)
.write_to_file(file);
Idle consumption is always computed beforehand, and is subtracted from the results. This cannot be disabled, which is by design. The default duration is one minute, however it can be increased with:
let builder = EnergyTool::new(the_function)
.with_idle_duration(Duration::from_secs(120));
However if you have to run a benchmark multiple times, for example with different input data, the idle consumption can be pre-computed.
Here from_default
is similar to from_data
, but it uses the default value for the input argument of sort
.
let builder = EnergyTool::from_default(sort)
.precompute_idle()?;
let json = builder.with_data(sorted).benchmark()?;
let json = builder.with_data(reversed).benchmark()?;
let json = builder.with_data(uniform).benchmark()?;
The benchmarked function might complete so quickly that no energy measurements could be obtained. To resolve this we expose two options; either the function can be repeated a fixed number of times, or the function can be repeated until some minimal amount of time has passed. By default, the function is benchmarked for at least 100 milliseconds.
let builder = EnergyTool::new(the_function)
.with_runs_per_measurement(100)
let builder = EnergyTool::new(the_function)
.with_min_measurement_duration(Duration::from_secs(1))
We support multiple measuring devices.
Currently, we support the features rapl
and ina
.