mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-24 21:26:28 +00:00
96 lines
3.0 KiB
Rust
96 lines
3.0 KiB
Rust
use criterion::{Criterion, black_box, criterion_group, criterion_main};
|
|
use rustfs_filemeta::{FileMeta, test_data::*};
|
|
|
|
fn bench_create_real_xlmeta(c: &mut Criterion) {
|
|
c.bench_function("create_real_xlmeta", |b| b.iter(|| black_box(create_real_xlmeta().unwrap())));
|
|
}
|
|
|
|
fn bench_create_complex_xlmeta(c: &mut Criterion) {
|
|
c.bench_function("create_complex_xlmeta", |b| b.iter(|| black_box(create_complex_xlmeta().unwrap())));
|
|
}
|
|
|
|
fn bench_parse_real_xlmeta(c: &mut Criterion) {
|
|
let data = create_real_xlmeta().unwrap();
|
|
|
|
c.bench_function("parse_real_xlmeta", |b| b.iter(|| black_box(FileMeta::load(&data).unwrap())));
|
|
}
|
|
|
|
fn bench_parse_complex_xlmeta(c: &mut Criterion) {
|
|
let data = create_complex_xlmeta().unwrap();
|
|
|
|
c.bench_function("parse_complex_xlmeta", |b| b.iter(|| black_box(FileMeta::load(&data).unwrap())));
|
|
}
|
|
|
|
fn bench_serialize_real_xlmeta(c: &mut Criterion) {
|
|
let data = create_real_xlmeta().unwrap();
|
|
let fm = FileMeta::load(&data).unwrap();
|
|
|
|
c.bench_function("serialize_real_xlmeta", |b| b.iter(|| black_box(fm.marshal_msg().unwrap())));
|
|
}
|
|
|
|
fn bench_serialize_complex_xlmeta(c: &mut Criterion) {
|
|
let data = create_complex_xlmeta().unwrap();
|
|
let fm = FileMeta::load(&data).unwrap();
|
|
|
|
c.bench_function("serialize_complex_xlmeta", |b| b.iter(|| black_box(fm.marshal_msg().unwrap())));
|
|
}
|
|
|
|
fn bench_round_trip_real_xlmeta(c: &mut Criterion) {
|
|
let original_data = create_real_xlmeta().unwrap();
|
|
|
|
c.bench_function("round_trip_real_xlmeta", |b| {
|
|
b.iter(|| {
|
|
let fm = FileMeta::load(&original_data).unwrap();
|
|
let serialized = fm.marshal_msg().unwrap();
|
|
black_box(FileMeta::load(&serialized).unwrap())
|
|
})
|
|
});
|
|
}
|
|
|
|
fn bench_round_trip_complex_xlmeta(c: &mut Criterion) {
|
|
let original_data = create_complex_xlmeta().unwrap();
|
|
|
|
c.bench_function("round_trip_complex_xlmeta", |b| {
|
|
b.iter(|| {
|
|
let fm = FileMeta::load(&original_data).unwrap();
|
|
let serialized = fm.marshal_msg().unwrap();
|
|
black_box(FileMeta::load(&serialized).unwrap())
|
|
})
|
|
});
|
|
}
|
|
|
|
fn bench_version_stats(c: &mut Criterion) {
|
|
let data = create_complex_xlmeta().unwrap();
|
|
let fm = FileMeta::load(&data).unwrap();
|
|
|
|
c.bench_function("version_stats", |b| b.iter(|| black_box(fm.get_version_stats())));
|
|
}
|
|
|
|
fn bench_validate_integrity(c: &mut Criterion) {
|
|
let data = create_real_xlmeta().unwrap();
|
|
let fm = FileMeta::load(&data).unwrap();
|
|
|
|
c.bench_function("validate_integrity", |b| {
|
|
b.iter(|| {
|
|
fm.validate_integrity().unwrap();
|
|
black_box(())
|
|
})
|
|
});
|
|
}
|
|
|
|
criterion_group!(
|
|
benches,
|
|
bench_create_real_xlmeta,
|
|
bench_create_complex_xlmeta,
|
|
bench_parse_real_xlmeta,
|
|
bench_parse_complex_xlmeta,
|
|
bench_serialize_real_xlmeta,
|
|
bench_serialize_complex_xlmeta,
|
|
bench_round_trip_real_xlmeta,
|
|
bench_round_trip_complex_xlmeta,
|
|
bench_version_stats,
|
|
bench_validate_integrity
|
|
);
|
|
|
|
criterion_main!(benches);
|