Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/magiclen/benchmarking
This crate can be used to execute something and measure the execution time in nano seconds. It does not output anything to the screen and the filesystem.
https://github.com/magiclen/benchmarking
benchmark rust
Last synced: 28 days ago
JSON representation
This crate can be used to execute something and measure the execution time in nano seconds. It does not output anything to the screen and the filesystem.
- Host: GitHub
- URL: https://github.com/magiclen/benchmarking
- Owner: magiclen
- License: mit
- Created: 2019-06-04T14:56:47.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-05-01T13:24:45.000Z (8 months ago)
- Last Synced: 2024-11-09T04:19:56.063Z (about 1 month ago)
- Topics: benchmark, rust
- Language: Rust
- Homepage:
- Size: 43 KB
- Stars: 3
- Watchers: 2
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Benchmarking
====================[![CI](https://github.com/magiclen/benchmarking/actions/workflows/ci.yml/badge.svg)](https://github.com/magiclen/benchmarking/actions/workflows/ci.yml)
This crate can be used to execute something and measure the execution time. It does not output anything to screens and filesystems.
## Examples
```rust
const VEC_LENGTH: usize = 100;benchmarking::warm_up();
let bench_result = benchmarking::measure_function(|measurer| {
let mut vec: Vec = Vec::with_capacity(VEC_LENGTH);unsafe {
vec.set_len(VEC_LENGTH);
}for i in 0..VEC_LENGTH {
measurer.measure(|| {
vec[i]
});
}vec
}).unwrap();println!("Reading a number from a vec takes {:?}!", bench_result.elapsed());
``````rust
const VEC_LENGTH: usize = 100;benchmarking::warm_up();
let bench_result = benchmarking::measure_function(|measurer| {
let mut vec: Vec = Vec::with_capacity(VEC_LENGTH);measurer.measure(|| {
for i in 0..VEC_LENGTH {
vec.push(i);
}
});vec
}).unwrap();println!("Filling 0 to 99 into a vec takes {:?}!", bench_result.elapsed());
``````rust
const VEC_LENGTH: usize = 100;benchmarking::warm_up();
let bench_result = benchmarking::measure_function(|measurer| {
let mut vec: Vec = Vec::with_capacity(VEC_LENGTH);for loop_seq in 0..VEC_LENGTH {
measurer.measure(|| {
vec.push(loop_seq);
});
}vec
}).unwrap();println!("Pushing a number into a vec takes {:?}!", bench_result.elapsed());
``````rust
const VEC_LENGTH: usize = 100;benchmarking::warm_up();
let bench_result = benchmarking::measure_function_n(2, |measurers| {
let mut vec: Vec = Vec::with_capacity(VEC_LENGTH);for i in 0..VEC_LENGTH {
measurers[1].measure(|| {
vec.push(i);
});
}for i in 0..VEC_LENGTH {
measurers[0].measure(|| {
vec[i]
});
}vec
}).unwrap();println!("Reading a number from a vec takes {:?}!", bench_result[0].elapsed());
println!("Pushing a number into a vec takes {:?}!", bench_result[1].elapsed());
```* The `warm_up` and `warm_up_with_duration` functions of the `benchmarking` crate runs on one thread. To warm up all CPUs, you can use the `warm_up_multi_thread` and `warm_up_multi_thread_with_duration` functions instead.
* The `measure_function` and `measure_function_with_times` functions of the `benchmarking` crate can execute a closure for N times. To execute it repeatly for a while instead, you can use the `bench_function` and `bench_function_with_duration` functions.
* To execute a closure with multiple threads to measure the throughput, you can use the `multi_thread_bench_function` and `multi_thread_bench_function_with_duration` functions of the `benchmarking` crate.## Crates.io
https://crates.io/crates/benchmarking
## Documentation
https://docs.rs/benchmarking
## License
[MIT](LICENSE)