1
0
Fork 0
mirror of https://github.com/alfg/mp4-rust.git synced 2024-05-19 16:58:04 +00:00

Merge pull request #25 from alfg/benchmarking

Benchmarking
This commit is contained in:
Alfred Gutierrez 2020-08-26 22:19:33 -07:00 committed by GitHub
commit 65b3408625
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 1 deletions

View file

@ -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

View file

@ -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
View 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);

View file

@ -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);
}