1
1
use clvmr:: allocator:: Allocator ;
2
2
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 ,
4
5
} ;
5
6
use criterion:: black_box;
6
7
use criterion:: { criterion_group, criterion_main, Criterion } ;
@@ -14,15 +15,28 @@ fn serialize_benchmark(c: &mut Criterion) {
14
15
let block0: & [ u8 ] = include_bytes ! ( "0.generator" ) ;
15
16
let block1: & [ u8 ] = include_bytes ! ( "1.generator" ) ;
16
17
let block2: & [ u8 ] = include_bytes ! ( "2.generator" ) ;
18
+ let block3: & [ u8 ] = include_bytes ! ( "3.generator" ) ;
19
+ let block4: & [ u8 ] = include_bytes ! ( "4.generator" ) ;
17
20
18
21
let mut group = c. benchmark_group ( "serialize" ) ;
19
22
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
+ ] {
21
30
let mut a = Allocator :: new ( ) ;
22
31
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
+ } ;
26
40
27
41
group. bench_function ( format ! ( "node_to_bytes_backrefs {name}" ) , |b| {
28
42
b. iter ( || {
0 commit comments