Skip to content

Commit 6094234

Browse files
authored
Merge pull request #249 from mozilla/avif-bench
Add a benchmark for measuring AVIF parsing performance
2 parents 1a09281 + bd85a88 commit 6094234

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

mp4parse/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,12 @@ static_assertions = "1.1.0"
3737
test-assembler = "0.1.2"
3838
env_logger = "0.7.1"
3939
walkdir = "2.3.1"
40+
criterion = "0.3"
41+
42+
[[bench]]
43+
name = "avif_benchmark"
44+
harness = false
45+
46+
# See https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options
47+
[lib]
48+
bench = false

mp4parse/benches/avif_benchmark.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
extern crate criterion;
5+
extern crate mp4parse as mp4;
6+
7+
use criterion::{criterion_group, criterion_main, Criterion};
8+
use std::fs::File;
9+
10+
fn criterion_benchmark(c: &mut Criterion) {
11+
c.bench_function("avif_largest", |b| b.iter(|| avif_largest()));
12+
}
13+
14+
criterion_group!(benches, criterion_benchmark);
15+
criterion_main!(benches);
16+
17+
fn avif_largest() {
18+
let context = &mut mp4::AvifContext::new();
19+
let input = &mut File::open(
20+
"av1-avif/testFiles/Netflix/avif/cosmos_frame05000_yuv444_12bpc_bt2020_pq_qlossless.avif",
21+
)
22+
.expect("Unknown file");
23+
assert!(mp4::read_avif(input, context).is_ok());
24+
}

0 commit comments

Comments
 (0)