Skip to content

Commit

Permalink
fixed benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
sokorototo committed Feb 11, 2025
1 parent 8a70993 commit 2220de1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
38 changes: 17 additions & 21 deletions crates/vach-benchmarks/benches/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,17 @@ pub fn criterion_benchmark(c: &mut Criterion) {
// Configure benchmark
builder_group.throughput(Throughput::Bytes((data_1.len() + data_2.len() + data_3.len()) as u64));

builder_group.bench_function("Builder::dump(---)", |b| {
builder_group.bench_function("dump(---)", |b| {
b.iter(|| {
let mut builder = Builder::new();

// Add data
builder
.add_leaf(Leaf::new(data_1, "d1").compress(CompressMode::Always))
.unwrap();
builder
.add_leaf(Leaf::new(data_2, "d2").compress(CompressMode::Never))
.unwrap();
builder
.add_leaf(Leaf::new(data_3, "d3").compress(CompressMode::Detect))
.unwrap();

// Dump data
builder.dump(Sink::new(), &b_config).unwrap();
// setup data
let mut leaves = [
Leaf::new(data_1, "d1").compress(CompressMode::Always),
Leaf::new(data_2, "d2").compress(CompressMode::Never),
Leaf::new(data_3, "d3").compress(CompressMode::Detect),
];

// dump
dump(Sink::new(), &mut leaves, &b_config, None).unwrap()
});
});

Expand All @@ -82,15 +76,17 @@ pub fn criterion_benchmark(c: &mut Criterion) {

{
// Builds an archive source from which to benchmark
let mut builder = Builder::new().template(Leaf::default().encrypt(false).sign(false));
let template = Leaf::default().encrypt(false).sign(false);

// Add data
builder.add(data_1, "d1").unwrap();
builder.add(data_2, "d2").unwrap();
builder.add(data_3, "d3").unwrap();
let mut leaves = [
Leaf::new(data_1, "d1").template(&template),
Leaf::new(data_2, "d2").template(&template),
Leaf::new(data_3, "d3").template(&template),
];

// Dump data
black_box(builder.dump(&mut target, &b_config).unwrap());
dump(&mut target, &mut leaves, &b_config, None).unwrap();
}

// Load data
Expand Down
1 change: 0 additions & 1 deletion crates/vach/src/loader/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ impl<T> Archive<T> {
}
}

// Add read layers
// 1: Decryption layer
if entry.flags.contains(Flags::ENCRYPTED_FLAG) {
#[cfg(feature = "crypto")]
Expand Down
1 change: 1 addition & 0 deletions crates/vach/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ fn consolidated_test() -> InternalResult {

// Quick assertions
let then = Instant::now();

assert_eq!(archive.fetch_mut("d1")?.data.as_ref(), data_1);
assert_eq!(archive.fetch_mut("d2")?.data.as_ref(), data_2);
assert_eq!(archive.fetch_mut("d3")?.data.as_ref(), data_3);
Expand Down
7 changes: 5 additions & 2 deletions crates/vach/src/writer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ pub use leaf::Leaf;
pub use {leaf::CompressMode, crate::global::compressor::Compressor};

use crate::global::error::*;
use crate::global::{header::Header, reg_entry::RegistryEntry, flags::Flags};
use crate::global::{header::Header, reg_entry::RegistryEntry};

#[cfg(feature = "crypto")]
use {crate::crypto::Encryptor, ed25519_dalek::Signer};
use {
crate::{crypto::Encryptor, global::flags::Flags},
ed25519_dalek::Signer,
};

#[cfg(not(feature = "crypto"))]
type Encryptor = ();
Expand Down

0 comments on commit 2220de1

Please sign in to comment.