This commit is contained in:
2026-02-03 11:14:25 +08:00
commit 8d6a720e8d
26 changed files with 35602 additions and 0 deletions

114
benches/benchmark.rs Normal file
View File

@@ -0,0 +1,114 @@
//! Benchmarks for wl-webrtc
//!
//! This module contains performance benchmarks using the Criterion library.
use criterion::{black_box, criterion_group, criterion_main, Criterion};
fn benchmark_config_parsing(c: &mut Criterion) {
let toml_str = r#"
[capture]
frame_rate = 60
quality = "high"
[encoder]
encoder_type = "h264_x264"
width = 1920
height = 1080
frame_rate = 60
bitrate = 8000000
max_bitrate = 10000000
min_bitrate = 500000
keyframe_interval = 30
[webrtc]
port = 9000
ice_servers = ["stun:stun.l.google.com:19302"]
"#;
c.bench_function("config parsing", |b| {
b.iter(|| {
let _ = toml::from_str::<wl_webrtc::config::AppConfig>(black_box(toml_str));
})
});
}
fn benchmark_config_validation(c: &mut Criterion) {
let config = wl_webrtc::config::AppConfig::default();
c.bench_function("config validation", |b| {
b.iter(|| {
let _ = black_box(&config).validate();
})
});
}
fn benchmark_config_serialization(c: &mut Criterion) {
let config = wl_webrtc::config::AppConfig::default();
c.bench_function("config serialization", |b| {
b.iter(|| {
let _ = toml::to_string(black_box(&config));
})
});
}
fn benchmark_cli_parsing(c: &mut Criterion) {
let args = vec![
"wl-webrtc",
"--frame-rate",
"60",
"--width",
"1920",
"--height",
"1080",
];
c.bench_function("cli parsing", |b| {
b.iter(|| {
let _ = wl_webrtc::config::Cli::try_parse_from(black_box(&args));
})
});
}
fn benchmark_config_merge(c: &mut Criterion) {
let mut config = wl_webrtc::config::AppConfig::default();
let overrides = wl_webrtc::config::ConfigOverrides {
frame_rate: Some(60),
width: Some(1280),
height: Some(720),
bitrate_mbps: None,
bitrate: Some(2_000_000),
port: Some(9000),
};
c.bench_function("config merge", |b| {
b.iter(|| {
let mut cfg = config.clone();
cfg.merge_cli_overrides(black_box(&overrides));
})
});
}
fn benchmark_encoder_latency(c: &mut Criterion) {}
fn benchmark_capture_latency(c: &mut Criterion) {}
fn benchmark_webrtc_latency(c: &mut Criterion) {}
criterion_group!(
benches,
benchmark_config_parsing,
benchmark_config_validation,
benchmark_config_serialization,
benchmark_cli_parsing,
benchmark_config_merge
);
criterion_group!(
latency_benches,
benchmark_encoder_latency,
benchmark_capture_latency,
benchmark_webrtc_latency
);
criterion_main!(benches, latency_benches);