mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-01-03 22:33:06 +00:00
WIP: Remove old benchmarks (#297)
* Remove old benchmarkmarking binaries now that we use Criterion. * Benchmark CrandallField alongside Goldilocks.
This commit is contained in:
parent
41b26e1f56
commit
ad30f4aca6
@ -2,16 +2,18 @@
|
||||
#![feature(generic_const_exprs)]
|
||||
|
||||
use criterion::{criterion_group, criterion_main, BatchSize, Criterion};
|
||||
use plonky2::field::crandall_field::CrandallField;
|
||||
use plonky2::field::goldilocks_field::GoldilocksField;
|
||||
use plonky2::hash::gmimc::GMiMC;
|
||||
use plonky2::hash::poseidon::Poseidon;
|
||||
use plonky2::hash::rescue::rescue;
|
||||
use tynm::type_name;
|
||||
|
||||
pub(crate) fn bench_gmimc<F: GMiMC<WIDTH>, const WIDTH: usize>(c: &mut Criterion) {
|
||||
c.bench_function(&format!("gmimc<{}, {}>", type_name::<F>(), WIDTH), |b| {
|
||||
b.iter_batched(
|
||||
|| F::rand_arr::<WIDTH>(),
|
||||
|mut state| F::gmimc_permute(state),
|
||||
|state| F::gmimc_permute(state),
|
||||
BatchSize::SmallInput,
|
||||
)
|
||||
});
|
||||
@ -24,13 +26,15 @@ where
|
||||
c.bench_function(&format!("poseidon<{}, {}>", type_name::<F>(), WIDTH), |b| {
|
||||
b.iter_batched(
|
||||
|| F::rand_arr::<WIDTH>(),
|
||||
|mut state| F::poseidon(state),
|
||||
|state| F::poseidon(state),
|
||||
BatchSize::SmallInput,
|
||||
)
|
||||
});
|
||||
}
|
||||
|
||||
fn criterion_benchmark(c: &mut Criterion) {
|
||||
bench_gmimc::<CrandallField, 12>(c);
|
||||
bench_poseidon::<CrandallField, 12>(c);
|
||||
bench_gmimc::<GoldilocksField, 12>(c);
|
||||
bench_poseidon::<GoldilocksField, 12>(c);
|
||||
}
|
||||
|
||||
@ -1,27 +0,0 @@
|
||||
//! Performs a single exponentiation.
|
||||
|
||||
use std::time::Instant;
|
||||
|
||||
use plonky2::field::crandall_field::CrandallField;
|
||||
use plonky2::field::field_types::Field;
|
||||
|
||||
type F = CrandallField;
|
||||
|
||||
const EXPONENT: usize = 1000000000;
|
||||
|
||||
fn main() {
|
||||
let base = F::rand();
|
||||
let mut state = F::ONE;
|
||||
|
||||
let start = Instant::now();
|
||||
for _ in 0..EXPONENT {
|
||||
state *= base;
|
||||
}
|
||||
let duration = start.elapsed();
|
||||
|
||||
println!("Result: {:?}", state);
|
||||
println!(
|
||||
"Average field mul: {:?}ns",
|
||||
duration.as_secs_f64() * 1e9 / EXPONENT as f64
|
||||
);
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
//! 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_types::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 base_i in bases.iter_mut() {
|
||||
*base_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
|
||||
);
|
||||
}
|
||||
@ -1,44 +0,0 @@
|
||||
use std::convert::TryInto;
|
||||
use std::thread;
|
||||
use std::time::Instant;
|
||||
|
||||
use plonky2::field::crandall_field::CrandallField;
|
||||
use plonky2::field::field_types::Field;
|
||||
use plonky2::hash::gmimc::GMiMC;
|
||||
|
||||
type F = CrandallField;
|
||||
|
||||
// 113 wire polys, 3 Z polys, 4 parts of quotient poly.
|
||||
const PROVER_POLYS: usize = 113 + 3 + 4;
|
||||
|
||||
fn main() {
|
||||
const THREADS: usize = 12;
|
||||
const LDE_BITS: i32 = 3;
|
||||
const W: usize = 12;
|
||||
const HASHES_PER_POLY: usize = 1 << ((13 + LDE_BITS) / 6);
|
||||
|
||||
let threads = (0..THREADS)
|
||||
.map(|_i| {
|
||||
thread::spawn(move || {
|
||||
let mut x: [F; W] = F::rand_vec(W).try_into().unwrap();
|
||||
|
||||
let hashes_per_thread = HASHES_PER_POLY * PROVER_POLYS / THREADS;
|
||||
let start = Instant::now();
|
||||
for _ in 0..hashes_per_thread {
|
||||
x = F::gmimc_permute(x);
|
||||
}
|
||||
let duration = start.elapsed();
|
||||
println!("took {:?}", duration);
|
||||
println!(
|
||||
"avg {:?}us",
|
||||
duration.as_secs_f64() * 1e6 / (hashes_per_thread as f64)
|
||||
);
|
||||
println!("result {:?}", x);
|
||||
})
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for t in threads {
|
||||
t.join().expect("oops");
|
||||
}
|
||||
}
|
||||
@ -1,85 +0,0 @@
|
||||
use std::time::Instant;
|
||||
|
||||
use plonky2::field::crandall_field::CrandallField as F;
|
||||
use plonky2::field::field_types::Field;
|
||||
use plonky2::hash::gmimc::GMiMC;
|
||||
use plonky2::hash::poseidon::Poseidon;
|
||||
use plonky2::hash::rescue::rescue;
|
||||
|
||||
#[inline]
|
||||
fn gmimc_hash<const W: usize>(x: [F; W]) -> [F; W]
|
||||
where
|
||||
F: GMiMC<W>,
|
||||
{
|
||||
F::gmimc_permute(x)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn rescue_hash(x: [F; 12]) -> [F; 12] {
|
||||
rescue(x)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn poseidon8_hash(x: [F; 8]) -> [F; 8] {
|
||||
F::poseidon(x)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn poseidon8_naive_hash(x: [F; 8]) -> [F; 8] {
|
||||
F::poseidon_naive(x)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn poseidon12_hash(x: [F; 12]) -> [F; 12] {
|
||||
F::poseidon(x)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn poseidon12_naive_hash(x: [F; 12]) -> [F; 12] {
|
||||
F::poseidon_naive(x)
|
||||
}
|
||||
|
||||
fn bench_hash<const W: usize>(name: &str, hash: fn([F; W]) -> [F; W], gmimc_tm: &mut f64) {
|
||||
// 113 wire polys, 3 Z polys, 4 parts of quotient poly.
|
||||
const PROVER_POLYS: usize = 113 + 3 + 4;
|
||||
const LDE_BITS: i32 = 3;
|
||||
const HASHES_PER_POLY: usize = 1 << (13 + LDE_BITS) / 6;
|
||||
const N_HASHES: usize = HASHES_PER_POLY * PROVER_POLYS;
|
||||
|
||||
let mut input = [F::ZERO; W];
|
||||
for i in 0..W {
|
||||
input[i] = F::from_canonical_u64((i as u64) * 123456 + 789);
|
||||
}
|
||||
|
||||
print!("{:16}", name);
|
||||
|
||||
let mut x = input;
|
||||
let start = Instant::now();
|
||||
for _ in 0..N_HASHES {
|
||||
x = hash(x);
|
||||
}
|
||||
let duration = start.elapsed();
|
||||
|
||||
let tm = duration.as_micros() as f64 / N_HASHES as f64;
|
||||
|
||||
if *gmimc_tm == 0.0 {
|
||||
*gmimc_tm = tm;
|
||||
}
|
||||
|
||||
println!(" {:5.2} {:5.2}", tm, tm / *gmimc_tm);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!(" -- Width 8 (time μs, slowdown wrt GMiMC)--");
|
||||
let mut tm: f64 = 0.0;
|
||||
// bench_hash("GMiMC", gmimc_hash::<8>, &mut tm); // Not implemented yet.
|
||||
bench_hash("Poseidon", poseidon8_hash, &mut tm);
|
||||
bench_hash("Poseidon naive", poseidon8_naive_hash, &mut tm);
|
||||
|
||||
println!("\n -- Width 12 (time μs, slowdown wrt GMiMC) --");
|
||||
let mut tm: f64 = 0.0;
|
||||
bench_hash("GMiMC", gmimc_hash::<12>, &mut tm);
|
||||
bench_hash("Poseidon", poseidon12_hash, &mut tm);
|
||||
bench_hash("Poseidon naive", poseidon12_naive_hash, &mut tm);
|
||||
bench_hash("Rescue", rescue_hash, &mut tm);
|
||||
}
|
||||
@ -1,44 +0,0 @@
|
||||
use std::convert::TryInto;
|
||||
use std::thread;
|
||||
use std::time::Instant;
|
||||
|
||||
use plonky2::field::crandall_field::CrandallField;
|
||||
use plonky2::field::field_types::Field;
|
||||
use plonky2::hash::rescue::rescue;
|
||||
|
||||
type F = CrandallField;
|
||||
|
||||
// 113 wire polys, 3 Z polys, 4 parts of quotient poly.
|
||||
const PROVER_POLYS: usize = 113 + 3 + 4;
|
||||
|
||||
fn main() {
|
||||
const THREADS: usize = 12;
|
||||
const LDE_BITS: i32 = 3;
|
||||
const W: usize = 12;
|
||||
const HASHES_PER_POLY: usize = (1 << (13 + LDE_BITS)) / 6;
|
||||
|
||||
let threads = (0..THREADS)
|
||||
.map(|_i| {
|
||||
thread::spawn(move || {
|
||||
let mut x: [F; W] = F::rand_vec(W).try_into().unwrap();
|
||||
|
||||
let hashes_per_thread = HASHES_PER_POLY * PROVER_POLYS / THREADS;
|
||||
let start = Instant::now();
|
||||
for _ in 0..hashes_per_thread {
|
||||
x = rescue(x);
|
||||
}
|
||||
let duration = start.elapsed();
|
||||
println!("took {:?}", duration);
|
||||
println!(
|
||||
"avg {:?}us",
|
||||
duration.as_secs_f64() * 1e6 / (hashes_per_thread as f64)
|
||||
);
|
||||
println!("result {:?}", x);
|
||||
})
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for t in threads {
|
||||
t.join().expect("oops");
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user