Skip to content

Commit

Permalink
Cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
cwlittle committed Jun 3, 2021
1 parent c833d00 commit 6eed08a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 71 deletions.
95 changes: 41 additions & 54 deletions benches/merk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ fn get_1m_rocksdb(c: &mut Criterion) {
}

let mut i = 0;
c.bench_function(
"get_1m_rocksdb",
|b| b.iter(|| {
c.bench_function("get_1m_rocksdb", |b| {
b.iter(|| {
let batch_index = (i % num_batches) as usize;
let key_index = (i / num_batches) as usize;

Expand All @@ -35,7 +34,7 @@ fn get_1m_rocksdb(c: &mut Criterion) {

i = (i + 1) % initial_size;
})
);
});
}

fn insert_1m_2k_seq_rocksdb_noprune(c: &mut Criterion) {
Expand All @@ -51,14 +50,13 @@ fn insert_1m_2k_seq_rocksdb_noprune(c: &mut Criterion) {
}

let mut i = initial_size / batch_size;
c.bench_function(
"insert_1m_2k_seq_rocksdb_noprune",
|b| b.iter(|| {
c.bench_function("insert_1m_2k_seq_rocksdb_noprune", |b| {
b.iter(|| {
let batch = make_batch_seq((i * batch_size)..((i + 1) * batch_size));
unsafe { merk.apply_unchecked(&batch, &[]).expect("apply failed") };
i += 1;
})
);
});
}

fn insert_1m_2k_rand_rocksdb_noprune(c: &mut Criterion) {
Expand All @@ -74,14 +72,13 @@ fn insert_1m_2k_rand_rocksdb_noprune(c: &mut Criterion) {
}

let mut i = initial_size / batch_size;
c.bench_function(
"insert_1m_2k_rand_rocksdb_noprune",
|b| b.iter(|| {
c.bench_function("insert_1m_2k_rand_rocksdb_noprune", |b| {
b.iter(|| {
let batch = make_batch_rand(batch_size, i);
unsafe { merk.apply_unchecked(&batch, &[]).expect("apply failed") };
i += 1;
})
);
});
}

fn update_1m_2k_seq_rocksdb_noprune(c: &mut Criterion) {
Expand All @@ -97,14 +94,13 @@ fn update_1m_2k_seq_rocksdb_noprune(c: &mut Criterion) {
}

let mut i = 0;
c.bench_function(
"update_1m_2k_seq_rocksdb_noprune",
|b| b.iter(|| {
c.bench_function("update_1m_2k_seq_rocksdb_noprune", |b| {
b.iter(|| {
let batch = make_batch_seq((i * batch_size)..((i + 1) * batch_size));
unsafe { merk.apply_unchecked(&batch, &[]).expect("apply failed") };
i = (i + 1) % (initial_size / batch_size);
})
);
});
}

fn update_1m_2k_rand_rocksdb_noprune(c: &mut Criterion) {
Expand All @@ -120,14 +116,13 @@ fn update_1m_2k_rand_rocksdb_noprune(c: &mut Criterion) {
}

let mut i = 0;
c.bench_function(
"update_1m_2k_rand_rocksdb_noprune",
|b| b.iter(|| {
c.bench_function("update_1m_2k_rand_rocksdb_noprune", |b| {
b.iter(|| {
let batch = make_batch_rand(batch_size, i);
unsafe { merk.apply_unchecked(&batch, &[]).expect("apply failed") };
i = (i + 1) % (initial_size / batch_size);
})
);
});
}

fn delete_1m_2k_rand_rocksdb_noprune(c: &mut Criterion) {
Expand All @@ -143,9 +138,8 @@ fn delete_1m_2k_rand_rocksdb_noprune(c: &mut Criterion) {
}

let mut i = 0;
c.bench_function(
"delete_1m_2k_rand_rocksdb_noprune",
|b| b.iter(|| {
c.bench_function("delete_1m_2k_rand_rocksdb_noprune", |b| {
b.iter(|| {
if i >= (initial_size / batch_size) {
println!("WARNING: too many bench iterations, whole tree deleted");
return;
Expand All @@ -154,7 +148,7 @@ fn delete_1m_2k_rand_rocksdb_noprune(c: &mut Criterion) {
unsafe { merk.apply_unchecked(&batch, &[]).expect("apply failed") };
i = (i + 1) % (initial_size / batch_size);
})
);
});
}

fn prove_1m_1_rand_rocksdb_noprune(c: &mut Criterion) {
Expand All @@ -171,9 +165,8 @@ fn prove_1m_1_rand_rocksdb_noprune(c: &mut Criterion) {
}

let mut i = 0;
c.bench_function(
"prove_1m_1_rand_rocksdb_noprune",
|b| b.iter(|| {
c.bench_function("prove_1m_1_rand_rocksdb_noprune", |b| {
b.iter(|| {
let batch = make_batch_rand(proof_size, i);
let mut keys = Vec::with_capacity(batch.len());
for (key, _) in batch {
Expand All @@ -185,7 +178,7 @@ fn prove_1m_1_rand_rocksdb_noprune(c: &mut Criterion) {
merk.commit(std::collections::LinkedList::new(), &[])
.unwrap();
})
);
});
}

fn build_trunk_chunk_1m_1_rand_rocksdb_noprune(c: &mut Criterion) {
Expand All @@ -200,12 +193,10 @@ fn build_trunk_chunk_1m_1_rand_rocksdb_noprune(c: &mut Criterion) {
unsafe { merk.apply_unchecked(&batch, &[]).expect("apply failed") };
}


let mut bytes = vec![];

c.bench_function(
"build_trunk_chunk_1m_1_rand_rocksdb_noprune",
|b| b.iter(|| {
c.bench_function("build_trunk_chunk_1m_1_rand_rocksdb_noprune", |b| {
b.iter(|| {
bytes.clear();

let (ops, _) = merk.walk(|walker| walker.unwrap().create_trunk_proof().unwrap());
Expand All @@ -214,7 +205,7 @@ fn build_trunk_chunk_1m_1_rand_rocksdb_noprune(c: &mut Criterion) {
merk.commit(std::collections::LinkedList::new(), &[])
.unwrap();
})
);
});

//Need to figure out how to support this in criterion
//This is to show throughput
Expand Down Expand Up @@ -243,15 +234,14 @@ fn chunkproducer_rand_1m_1_rand_rocksdb_noprune(c: &mut Criterion) {
let index = rng.gen::<usize>() % chunks.len();
chunks.chunk(index).unwrap()
};
c.bench_function(
"chunkproducer_rand_1m_1_rand_rocksdb_noprune",
|b| b.iter(|| {
c.bench_function("chunkproducer_rand_1m_1_rand_rocksdb_noprune", |b| {
b.iter(|| {
let chunk = next();
total_bytes += chunk.len();
i += 1;
})
);
});

//b.bytes = (total_bytes / i) as u64;
}

Expand All @@ -278,15 +268,14 @@ fn chunk_iter_1m_1_rand_rocksdb_noprune(c: &mut Criterion) {
chunks.next().unwrap()
}
};
c.bench_function(
"chunk_iter_1m_1_rand_rocksdb_noprune",
|b| b.iter(|| {
c.bench_function("chunk_iter_1m_1_rand_rocksdb_noprune", |b| {
b.iter(|| {
let chunk = next();
total_bytes += chunk.unwrap().len();
i += 1;
})
);
});

//b.bytes = (total_bytes / i) as u64;
}

Expand Down Expand Up @@ -314,10 +303,9 @@ fn restore_1m_1_rand_rocksdb_noprune(c: &mut Criterion) {

let mut total_bytes = 0;
let mut i = 0;

c.bench_function(
"restore_1m_1_rand_rocksdb_noprune",
|b| b.iter(|| {

c.bench_function("restore_1m_1_rand_rocksdb_noprune", |b| {
b.iter(|| {
if i % chunks.len() == 0 {
if i != 0 {
let restorer_merk = restorer.take().unwrap().finalize();
Expand All @@ -335,7 +323,7 @@ fn restore_1m_1_rand_rocksdb_noprune(c: &mut Criterion) {
total_bytes += chunk.len();
i += 1;
})
);
});

std::fs::remove_dir_all(&path).unwrap();

Expand All @@ -355,19 +343,18 @@ fn checkpoint_create_destroy_1m_1_rand_rocksdb_noprune(c: &mut Criterion) {
}

let path = path + ".checkpoint";
c.bench_function(
"checkpoint_create_destroy_1m_1_rand_rocksdb_noprune",
|b| b.iter(|| {
c.bench_function("checkpoint_create_destroy_1m_1_rand_rocksdb_noprune", |b| {
b.iter(|| {
let checkpoint = merk.checkpoint(&path).unwrap();
checkpoint.destroy().unwrap();
})
);
});
}

criterion_group!{
criterion_group! {
name = merk;
config = Criterion::default();
targets = get_1m_rocksdb,
targets = get_1m_rocksdb,
insert_1m_2k_seq_rocksdb_noprune,
insert_1m_2k_rand_rocksdb_noprune,
update_1m_2k_seq_rocksdb_noprune,
Expand Down
30 changes: 13 additions & 17 deletions benches/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ fn insert_1m_10k_seq_memonly(c: &mut Criterion) {
let mut tree = Owner::new(make_tree_seq(initial_size));

let mut i = initial_size / batch_size;
c.bench_function(
"insert_1m_10k_seq_memonly",
|b| b.iter(|| {
c.bench_function("insert_1m_10k_seq_memonly", |b| {
b.iter(|| {
let batch = make_batch_seq((i * batch_size)..((i + 1) * batch_size));
tree.own(|tree| apply_memonly_unchecked(tree, &batch));
i += 1;
})
);
});
}

fn insert_1m_10k_rand_memonly(c: &mut Criterion) {
Expand All @@ -28,14 +27,13 @@ fn insert_1m_10k_rand_memonly(c: &mut Criterion) {
let mut tree = Owner::new(make_tree_rand(initial_size, batch_size, 0));

let mut i = initial_size / batch_size;
c.bench_function(
"insert_1m_10k_rand_memonly",
|b| b.iter(|| {
c.bench_function("insert_1m_10k_rand_memonly", |b| {
b.iter(|| {
let batch = make_batch_rand(batch_size, i);
tree.own(|tree| apply_memonly_unchecked(tree, &batch));
i += 1;
})
);
});
}

fn update_1m_10k_seq_memonly(c: &mut Criterion) {
Expand All @@ -45,14 +43,13 @@ fn update_1m_10k_seq_memonly(c: &mut Criterion) {
let mut tree = Owner::new(make_tree_seq(initial_size));

let mut i = 0;
c.bench_function(
"update_1m_10k_seq_memonly",
|b| b.iter(|| {
c.bench_function("update_1m_10k_seq_memonly", |b| {
b.iter(|| {
let batch = make_batch_seq((i * batch_size)..((i + 1) * batch_size));
tree.own(|tree| apply_memonly_unchecked(tree, &batch));
i = (i + 1) % (initial_size / batch_size);
})
);
});
}

fn update_1m_10k_rand_memonly(c: &mut Criterion) {
Expand All @@ -62,17 +59,16 @@ fn update_1m_10k_rand_memonly(c: &mut Criterion) {
let mut tree = Owner::new(make_tree_rand(initial_size, batch_size, 0));

let mut i = 0;
c.bench_function(
"update_1m_10k_rand_memonly",
|b| b.iter(|| {
c.bench_function("update_1m_10k_rand_memonly", |b| {
b.iter(|| {
let batch = make_batch_rand(batch_size, i);
tree.own(|tree| apply_memonly_unchecked(tree, &batch));
i = (i + 1) % (initial_size / batch_size);
})
);
});
}

criterion_group!{
criterion_group! {
name = ops;
config = Criterion::default();
targets = insert_1m_10k_seq_memonly,
Expand Down

0 comments on commit 6eed08a

Please sign in to comment.