Skip to content

Commit 06ab140

Browse files
committed
Restore the Binius RAM measurement code
1 parent 98fc1f1 commit 06ab140

File tree

1 file changed

+78
-3
lines changed

1 file changed

+78
-3
lines changed

binius/src/bin/measure.rs

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,88 @@
1+
#[global_allocator]
2+
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
3+
14
use anyhow::Error;
2-
use binius::bench::{prove, sha256_no_lookup_prepare, verify};
5+
use binius::bench::{prove, sha256_no_lookup_prepare, sha256_with_lookup_prepare};
6+
use binius_utils::{SerializationMode, SerializeBytes};
7+
use jemalloc_ctl::{
8+
epoch,
9+
stats::{self},
10+
};
311

412
fn main() -> Result<(), Error> {
13+
// No-lookup sha256
14+
epoch::advance().unwrap();
15+
let resident_before = stats::resident::read().unwrap();
16+
517
let allocator = bumpalo::Bump::new();
618
let (constraint_system, args, witness, backend) = sha256_no_lookup_prepare(&allocator);
719

8-
let (cs, args, proof) = prove(constraint_system, args, witness, backend);
20+
epoch::advance().unwrap();
21+
let resident_after = stats::resident::read().unwrap();
22+
23+
println!(
24+
"Preprocessing: resident memory (no lookup): {} MB",
25+
(resident_after - resident_before) as f32 / 1024.0 / 1024.0,
26+
);
27+
28+
let mut write_buf = vec![];
29+
constraint_system
30+
.serialize(&mut write_buf, SerializationMode::Native)
31+
.unwrap();
32+
let len = write_buf.len();
33+
println!(
34+
"Constraint system size (no lookup): {} KB",
35+
len as f32 / 1024.0
36+
);
37+
38+
epoch::advance().unwrap();
39+
let resident_before = stats::resident::read().unwrap();
40+
41+
let (_, _, _) = prove(constraint_system, args, witness, backend);
42+
43+
epoch::advance().unwrap();
44+
let resident_after = stats::resident::read().unwrap();
45+
println!(
46+
"Proving: resident memory (no lookup): {} MB",
47+
(resident_after - resident_before) as f32 / 1024.0 / 1024.0,
48+
);
49+
50+
//Lookup sha256
51+
epoch::advance().unwrap();
52+
let resident_before = stats::resident::read().unwrap();
53+
54+
let allocator = bumpalo::Bump::new();
55+
let (constraint_system, args, witness, backend) = sha256_with_lookup_prepare(&allocator);
56+
57+
epoch::advance().unwrap();
58+
let resident_after = stats::resident::read().unwrap();
59+
60+
println!(
61+
"Preprocessing: resident memory (with lookup): {} MB",
62+
(resident_after - resident_before) as f32 / 1024.0 / 1024.0,
63+
);
64+
65+
let mut write_buf = vec![];
66+
constraint_system
67+
.serialize(&mut write_buf, SerializationMode::Native)
68+
.unwrap();
69+
let len = write_buf.len();
70+
println!(
71+
"Constraint system size (with lookup): {} KB",
72+
len as f32 / 1024.0
73+
);
74+
75+
epoch::advance().unwrap();
76+
let resident_before = stats::resident::read().unwrap();
77+
78+
let (_, _, _) = prove(constraint_system, args, witness, backend);
979

10-
verify(cs, args, proof);
80+
epoch::advance().unwrap();
81+
let resident_after = stats::resident::read().unwrap();
82+
println!(
83+
"Proving: resident memory (with lookup): {} MB",
84+
(resident_after - resident_before) as f32 / 1024.0 / 1024.0,
85+
);
1186

1287
Ok(())
1388
}

0 commit comments

Comments
 (0)