Skip to content

Commit

Permalink
Add benchmark for JITgen (#2260)
Browse files Browse the repository at this point in the history
Adds the benchmark I used for measuring the witness generation JIT in
#2242.
  • Loading branch information
georgwiese authored Dec 20, 2024
1 parent d5c8a1e commit 64ce967
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pipeline/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ walkdir = "2.4.0"
name = "evaluator_benchmark"
harness = false

[[bench]]
name = "jit_witgen_benchmark"
harness = false

[lints]
workspace = true

Expand Down
25 changes: 25 additions & 0 deletions pipeline/benches/jit_witgen_benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use ::powdr_pipeline::Pipeline;
use powdr_number::GoldilocksField;

use criterion::{criterion_group, criterion_main, Criterion};

type T = GoldilocksField;

fn jit_witgen_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("jit-witgen-benchmark");
group.sample_size(10);

// Poseidon benchmark
let mut pipeline =
Pipeline::<T>::default().from_file("../test_data/std/poseidon_benchmark.asm".into());
pipeline.compute_optimized_pil().unwrap();
pipeline.compute_fixed_cols().unwrap();

group.bench_function("jit_witgen_benchmark", |b| {
b.iter(|| pipeline.clone().compute_witness().unwrap())
});
group.finish();
}

criterion_group!(benches_jit_witgen, jit_witgen_benchmark);
criterion_main!(benches_jit_witgen);
33 changes: 33 additions & 0 deletions test_data/std/poseidon_benchmark.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use std::machines::hash::poseidon_gl::PoseidonGL;

// 2^17 rows -> ~2^16 Poseidon hashes
machine Main with degree: 131072 {
reg pc[@pc];
reg X0[<=];
reg X1[<=];
reg X2[<=];
reg X3[<=];
reg X4[<=];
reg A;
reg B;
reg C;
reg D;

// 2^16 Poseidon hashes -> 2^21 rows in Poseidon machine
PoseidonGL poseidon(2097152, 2097152);

instr jmp l: label { pc' = l }

// Hash some constants (except the first element, to trick the loop detection)
instr poseidon X4 -> X0, X1, X2, X3
link ~> (X0, X1, X2, X3) = poseidon.poseidon_permutation(X4, 235763497586, 9827635653498, 112870, 289273673480943876, 230295874986745876, 6254867324987, 2087, 0, 0, 0, 0);

function main {

loop:
A, B, C, D <== poseidon(A);
jmp loop;

return;
}
}

0 comments on commit 64ce967

Please sign in to comment.