| 1 |
use std::hint::black_box; |
| 2 |
|
| 3 |
use criterion::{Criterion, criterion_group, criterion_main}; |
| 4 |
|
| 5 |
pub const TEST_VIDEOS: &[(&str, &str)] = &[ |
| 6 |
( |
| 7 |
"https://download.blender.org/demo/movies/ToS/tearsofsteel_4k.mov", |
| 8 |
"tearsofsteel_4k.mov", |
| 9 |
), |
| 10 |
( |
| 11 |
"https://download.blender.org/demo/movies/ToS/tears_of_steel_720p.mov", |
| 12 |
"tears_of_steel_720p.mov", |
| 13 |
), |
| 14 |
]; |
| 15 |
|
| 16 |
pub fn criterion_benchmark(c: &mut Criterion) { |
| 17 |
for (video_url, video_file) in TEST_VIDEOS { |
| 18 |
let path = format!("benches/{video_file}"); |
| 19 |
if std::fs::File::open(&path).is_err() { |
| 20 |
eprintln!("Downloading video data from <{video_url}>.\nThis might take a while …"); |
| 21 |
|
| 22 |
std::process::Command::new("curl") |
| 23 |
.args([video_url, "--output", path.as_str()]) |
| 24 |
.status() |
| 25 |
.unwrap(); |
| 26 |
} |
| 27 |
|
| 28 |
c.bench_function(video_file, |b| b.iter(|| run_thumbnailer(black_box(&path)))); |
| 29 |
} |
| 30 |
eprintln!( |
| 31 |
"Used GStreamer version:\n{}", |
| 32 |
std::process::Command::new("gst-launch-1.0") |
| 33 |
.arg("--version") |
| 34 |
.output() |
| 35 |
.ok() |
| 36 |
.map(|x| String::from_utf8_lossy(&x.stdout).to_string()) |
| 37 |
.unwrap_or_else(|| String::from("'gst-launch-1.0 --version' failed")) |
| 38 |
) |
| 39 |
} |
| 40 |
|
| 41 |
criterion_group!(benches, criterion_benchmark); |
| 42 |
criterion_main!(benches); |
| 43 |
|
| 44 |
fn run_thumbnailer(video: &str) { |
| 45 |
gst_thumbnailers::main_video_thumbnailer([ |
| 46 |
"gst-video-thumbnailer", |
| 47 |
"-p", |
| 48 |
video, |
| 49 |
"-o", |
| 50 |
"/dev/null", |
| 51 |
"-s", |
| 52 |
"256", |
| 53 |
]) |
| 54 |
.unwrap(); |
| 55 |
} |