Skip to content

Commit 8dd622c

Browse files
scottlambdholroyd
authored andcommitted
resurrect bench
* fix compilation, which broke with 9093549. Criterion changed Throughput::Bytes to take a u64 rather than a u32 as part of the 0.2 -> 0.3 update. * build on CI so this doesn't break again. * add instructions for generating input data, and .gitignore it. * fix warnings.
1 parent d99afd2 commit 8dd622c

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

.github/workflows/rust.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ jobs:
1414
steps:
1515
- uses: actions/checkout@v2
1616
- name: Build
17-
run: cargo build --verbose
17+
run: cargo build --verbose --all-targets
1818
- name: Run tests
1919
run: cargo test --verbose

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/big_buck_bunny_1080p_h264.mov
2+
/big_buck_bunny_1080p.h264
13
/target/
24
**/*.swp
35
Cargo.lock

benches/bench.rs

+20-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1+
//! Benchmark on a large video file.
2+
//!
3+
//! Expects a copy of [Big Buck Bunny](https://peach.blender.org/download/):
4+
//! ```text
5+
//! $ curl --OL https://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_1080p_h264.mov
6+
//! $ ffmpeg -i big_buck_bunny_1080p_h264.mov -c copy big_buck_bunny_1080p.h264
7+
//! ```
8+
19
#[macro_use]
210
extern crate criterion;
311
extern crate h264_reader;
412

513
use criterion::Criterion;
614
use std::fs::File;
7-
use criterion::Benchmark;
815
use criterion::Throughput;
16+
use std::convert::TryFrom;
917
use std::io::Read;
1018
use h264_reader::annexb::AnnexBReader;
1119
use h264_reader::annexb::NalReader;
@@ -33,7 +41,7 @@ impl NalHandler for NullNalHandler {
3341
}
3442

3543
struct NullNalReader {
36-
decoder: RbspDecoder<NullNalHandler>,
44+
_decoder: RbspDecoder<NullNalHandler>,
3745
start: u64,
3846
push: u64,
3947
end: u64,
@@ -53,26 +61,29 @@ impl NalReader for NullNalReader {
5361
}
5462

5563
fn h264_reader(c: &mut Criterion) {
56-
let mut f = File::open("big_buck_bunny_1080p_24fps_h264.h264").expect("file not found");
57-
let size = f.metadata().unwrap().len() as usize;
58-
let mut buf = vec![0; size];
64+
let mut f = File::open("big_buck_bunny_1080p.h264").expect("file not found");
65+
let len = f.metadata().unwrap().len();
66+
let mut buf = vec![0; usize::try_from(len).unwrap()];
5967
f.read(&mut buf[..]).unwrap();
6068
let mut ctx = Context::default();
6169
let nal_handler = NullNalHandler {};
6270
let nal_reader = NullNalReader {
63-
decoder: RbspDecoder::new(nal_handler),
71+
_decoder: RbspDecoder::new(nal_handler),
6472
start: 0,
6573
push: 0,
6674
end: 0,
6775
};
6876
let mut annexb_reader = AnnexBReader::new(nal_reader);
69-
c.bench("parse", Benchmark::new("parse", move |b| {
77+
78+
let mut group = c.benchmark_group("parse");
79+
group.throughput(Throughput::Bytes(len));
80+
group.bench_function("parse", move |b| {
7081
b.iter(|| {
7182
annexb_reader.start(&mut ctx);
7283
annexb_reader.push(&mut ctx, &buf[..]);
7384
annexb_reader.end_units(&mut ctx);
74-
} );
75-
}).throughput(Throughput::Bytes(size as u32)));
85+
})
86+
});
7687
}
7788

7889
criterion_group!(benches, h264_reader);

0 commit comments

Comments
 (0)