Skip to content

Commit 517ec32

Browse files
committed
Add two new serializer benchmarks trees
1 parent b2d9d69 commit 517ec32

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

benches/3.generator

10.8 KB
Binary file not shown.

benches/4.generator

1002 Bytes
Binary file not shown.

benches/serialize.rs

+19-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use clvmr::allocator::Allocator;
22
use clvmr::serde::{
3-
node_from_bytes, node_from_bytes_backrefs, node_to_bytes, node_to_bytes_backrefs, Serializer,
3+
node_from_bytes, node_from_bytes_backrefs, node_to_bytes_backrefs, node_to_bytes_limit,
4+
Serializer,
45
};
56
use criterion::black_box;
67
use criterion::{criterion_group, criterion_main, Criterion};
@@ -14,15 +15,28 @@ fn serialize_benchmark(c: &mut Criterion) {
1415
let block0: &[u8] = include_bytes!("0.generator");
1516
let block1: &[u8] = include_bytes!("1.generator");
1617
let block2: &[u8] = include_bytes!("2.generator");
18+
let block3: &[u8] = include_bytes!("3.generator");
19+
let block4: &[u8] = include_bytes!("4.generator");
1720

1821
let mut group = c.benchmark_group("serialize");
1922

20-
for (block, name) in [(&block0, "0"), (&block1, "1"), (&block2, "2")] {
23+
for (block, name) in [
24+
(&block0, "0"),
25+
(&block1, "1"),
26+
(&block2, "2"),
27+
(&block3, "3"),
28+
(&block4, "4"),
29+
] {
2130
let mut a = Allocator::new();
2231
let node = node_from_bytes_backrefs(&mut a, block).expect("node_from_bytes_backrefs");
23-
let inflated = node_to_bytes(&a, node).expect("node_to_bytes");
24-
let mut a = Allocator::new();
25-
let node = node_from_bytes(&mut a, inflated.as_slice()).expect("node_from_bytes");
32+
33+
// if the inflated form takes too much space, just run the benchmark on the compact form
34+
let node = if let Ok(inflated) = node_to_bytes_limit(&a, node, 2000000) {
35+
a = Allocator::new();
36+
node_from_bytes(&mut a, inflated.as_slice()).expect("node_from_bytes")
37+
} else {
38+
node
39+
};
2640

2741
group.bench_function(format!("node_to_bytes_backrefs {name}"), |b| {
2842
b.iter(|| {

0 commit comments

Comments
 (0)