mirror of
https://github.com/alfg/mp4-rust.git
synced 2024-12-22 12:06:33 +00:00
add criterion for benchmarking performance.
This commit is contained in:
parent
6d1da78160
commit
be92897be6
4 changed files with 38 additions and 1 deletions
|
@ -22,3 +22,10 @@ thiserror = "^1.0"
|
|||
byteorder = "1"
|
||||
bytes = "0.5"
|
||||
num-rational = "0.3"
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = "0.3"
|
||||
|
||||
[[bench]]
|
||||
name = "bench_main"
|
||||
harness = false
|
|
@ -81,6 +81,14 @@ With print statement output.
|
|||
cargo test -- --nocapture
|
||||
```
|
||||
|
||||
#### Run Benchmark Tests
|
||||
```
|
||||
cargo bench
|
||||
```
|
||||
|
||||
View HTML report at `target/criterion/report/index.html`
|
||||
|
||||
|
||||
## Resources
|
||||
Thanks to the following resources used when learning Rust:
|
||||
* https://github.com/mozilla/mp4parse-rust
|
||||
|
|
22
benches/bench_main.rs
Normal file
22
benches/bench_main.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
use criterion::BenchmarkId;
|
||||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
use mp4;
|
||||
use std::fs::File;
|
||||
|
||||
fn read_mp4(filename: &str) -> u64 {
|
||||
let f = File::open(filename).unwrap();
|
||||
let m = mp4::read_mp4(f).unwrap();
|
||||
let size = m.size();
|
||||
size
|
||||
}
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
let filename = "tests/samples/minimal.mp4";
|
||||
|
||||
c.bench_with_input(BenchmarkId::new("input_example", filename), &filename, |b, &s| {
|
||||
b.iter(|| read_mp4(s));
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
criterion_main!(benches);
|
|
@ -6,7 +6,7 @@ fn main() {
|
|||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
if args.len() < 2 {
|
||||
println!("Usage: mp4dump <filename>");
|
||||
println!("Usage: simple <filename>");
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue