Add bench_field_mul_interleaved benchmark

This commit is contained in:
Daniel Lubarov 2021-04-09 10:26:21 -07:00
parent 0c07fcf0ae
commit f807db388b
2 changed files with 45 additions and 8 deletions

View File

@ -1,3 +1,5 @@
//! Performs a single exponentiation.
use std::time::Instant;
use plonky2::field::crandall_field::CrandallField;
@ -5,17 +7,19 @@ use plonky2::field::field::Field;
type F = CrandallField;
const EXPONENT: usize = 1000000000;
fn main() {
let m = F::from_canonical_u64(12345678901234567890);
let mut x = F::ONE;
let base = F::rand();
let mut state = F::ONE;
let start = Instant::now();
let num_muls = 2000000000;
for _ in 0..num_muls {
x *= m;
for _ in 0..EXPONENT {
state *= base;
}
let duration = start.elapsed();
println!("result {:?}", x);
println!("took {:?}", duration);
println!("avg {:?}ns", duration.as_secs_f64() * 1e9 / (num_muls as f64));
println!("Result: {:?}", state);
println!("Average field mul: {:?}ns",
duration.as_secs_f64() * 1e9 / EXPONENT as f64);
}

View File

@ -0,0 +1,33 @@
//! Performs several exponentiations in an interleaved loop, to enable parallelism on the core.
use std::time::Instant;
use plonky2::field::crandall_field::CrandallField;
use plonky2::field::field::Field;
type F = CrandallField;
/// The number of exponentiations to perform in parallel.
const WIDTH: usize = 6;
const EXPONENT: usize = 1000000000;
fn main() {
let mut bases = [F::ZERO; WIDTH];
for i in 0..WIDTH {
bases[i] = F::rand();
}
let mut state = [F::ONE; WIDTH];
let start = Instant::now();
for _ in 0..EXPONENT {
for i in 0..WIDTH {
state[i] *= bases[i];
}
}
let duration = start.elapsed();
println!("Result: {:?}", state);
println!("Average field mul: {:?}ns",
duration.as_secs_f64() * 1e9 / (WIDTH * EXPONENT) as f64);
}