agama/rust/zypp-agama/benches/list_patterns.rs
2026-05-20 11:57:56 +05:30

53 lines
1.5 KiB
Rust

use std::fs;
use criterion::{criterion_group, criterion_main, Criterion};
fn criterion_benchmark(c: &mut Criterion) {
let _ = fs::remove_dir_all("/tmp/zypp");
fs::create_dir_all("/tmp/zypp").unwrap();
let zypp = zypp_agama::Zypp::init_target(
"/tmp/zypp",
zypp_agama::callbacks::empty_init_target_progress,
)
.unwrap();
const GPG_KEYS: &str = "/usr/lib/rpm/gnupg/keys/gpg-*";
for file in glob::glob(GPG_KEYS).unwrap() {
match file {
Ok(file) => {
if let Err(e) = zypp.import_gpg_key(&file.to_string_lossy()) {
tracing::error!("Failed to import GPG key: {}", e);
}
}
Err(e) => {
tracing::error!("Could not read GPG key file: {}", e);
}
}
}
zypp.add_repository(
"tw",
"https://download.opensuse.org/tumbleweed/repo/oss/",
None,
|_, _| true,
)
.unwrap();
zypp.refresh_repository(
"tw",
&zypp_agama::callbacks::download_progress::EmptyCallback,
&mut zypp_agama::callbacks::security::EmptyCallback,
)
.unwrap();
zypp.load_source(
zypp_agama::callbacks::empty_progress,
&mut zypp_agama::callbacks::security::EmptyCallback,
)
.unwrap();
c.bench_function("list patterns", |b| {
b.iter(|| zypp.list_patterns().unwrap())
});
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);