https://github.com/juzi5201314/bench-rs
A benchmark library.
https://github.com/juzi5201314/bench-rs
bench bench-rs benchmark rust
Last synced: 12 months ago
JSON representation
A benchmark library.
- Host: GitHub
- URL: https://github.com/juzi5201314/bench-rs
- Owner: juzi5201314
- License: mit
- Created: 2020-09-21T12:10:57.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-10-03T03:40:18.000Z (over 5 years ago)
- Last Synced: 2025-06-15T10:55:52.029Z (about 1 year ago)
- Topics: bench, bench-rs, benchmark, rust
- Language: Rust
- Homepage:
- Size: 68.4 KB
- Stars: 15
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bench-rs

[](https://docs.rs/bench-rs)



[](https://crates.io/crates/bench-rs)
A benchmark library.
- [x] Stable rust (no black_box)
- [x] Beautiful output
- [x] Async support
- [x] Custom async runtime
- [x] Memory usage
- [x] Custom formatting
- [ ] Intuitive numerical units
- [x] Support custom memory allocator
### Examples
```
$ cargo test --release --color=always -q --package bench-rs --test bench --no-fail-fast -- --test-threads=1 --nocapture
```
Look `./tests/bench.rs`

### black_box
I don't know how to implement the black box.
Please use [core::hint::black_box](https://doc.rust-lang.org/core/hint/fn.black_box.html). (unstable)
If you have a better idea, welcome to submit a pull request or open an issue
### global_allocator
In order to detect Memory usage, `bench-rs` modified global_allocator.
This will make it impossible to use other allocators.
If you need to use other allocator:
Change your allocator: (if your allocator is `std::alloc::System`)
```
use std::alloc::System;
use bench_rs::{TrackAllocator, new_allocator};
#[global_allocator]
pub static GLOBAL: TrackAllocator = new_allocator!(System);
```
Turn off default features:
```
[dependencies]
bench-rs = { version = "*", default-features = false }
```
Import the allocator named `GLOBAL`:
```
use bench_rs::bench;
use yourlib::GLOBAL;
#[bench]
fn ...
```
If your allocator name is not `GLOBAL`, please set its alias to `GLOBAL`:
`use yourlib::OtherAllocator as GLOBAL`
Because the bencher-macro will look for `GLOBAL.counter()` and `GLOBAL.peak()`
at the same level of the bench function.
---
> I am a rust beginner, please correct me if the code is bad. Thank you
>
> Contributions welcome