Files
rustfs/crates/filemeta/benches/xl_meta_bench.rs
houseme 2e14b32ccd chore: Add copyright and license headers (#23)
* chore: Add copyright and license headers

This commit adds the Apache 2.0 license and a copyright notice to the header of all source files. This ensures that the licensing and copyright information is clearly stated within the codebase.

* cargo fmt

* fix

* fmt

* fix clippy
2025-07-02 15:07:47 +08:00

110 lines
3.5 KiB
Rust

// Copyright 2024 RustFS Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
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);