From 6949d04c72ea82378ce43e61c811a92b94cbd46b Mon Sep 17 00:00:00 2001 From: Jakub Nabaglo Date: Tue, 24 Aug 2021 11:56:00 -0700 Subject: [PATCH] Field arithmetic benchmark improvements (#200) * Field arithmetic benchmark improvements * Separate throughput/latency benchmarks * Widen addition throughput benchmark --- benches/field_arithmetic.rs | 76 +++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 3 deletions(-) diff --git a/benches/field_arithmetic.rs b/benches/field_arithmetic.rs index 47c11b45..b8fef443 100644 --- a/benches/field_arithmetic.rs +++ b/benches/field_arithmetic.rs @@ -1,3 +1,5 @@ +#![feature(destructuring_assignment)] + use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; use plonky2::field::crandall_field::CrandallField; use plonky2::field::extension_field::quartic::QuarticCrandallField; @@ -5,10 +7,78 @@ use plonky2::field::field_types::Field; use tynm::type_name; pub(crate) fn bench_field(c: &mut Criterion) { - c.bench_function(&format!("mul<{}>", type_name::()), |b| { + c.bench_function(&format!("mul-throughput<{}>", type_name::()), |b| { b.iter_batched( - || (F::rand(), F::rand()), - |(x, y)| x * y, + || (F::rand(), F::rand(), F::rand(), F::rand()), + |(mut x, mut y, mut z, mut w)| { + for _ in 0..25 { + (x, y, z, w) = (x * y, y * z, z * w, w * x); + } + (x, y, z, w) + }, + BatchSize::SmallInput, + ) + }); + + c.bench_function(&format!("mul-latency<{}>", type_name::()), |b| { + b.iter_batched( + || F::rand(), + |(mut x)| { + for _ in 0..100 { + x = x * x; + } + x + }, + BatchSize::SmallInput, + ) + }); + + c.bench_function(&format!("add-throughput<{}>", type_name::()), |b| { + b.iter_batched( + || { + ( + F::rand(), + F::rand(), + F::rand(), + F::rand(), + F::rand(), + F::rand(), + F::rand(), + F::rand(), + F::rand(), + F::rand(), + ) + }, + |(mut a, mut b, mut c, mut d, mut e, mut f, mut g, mut h, mut i, mut j)| { + for _ in 0..10 { + (a, b, c, d, e, f, g, h, i, j) = ( + a + b, + b + c, + c + d, + d + e, + e + f, + f + g, + g + h, + h + i, + i + j, + j + a, + ); + } + (a, b, c, d, e, f, g, h, i, j) + }, + BatchSize::SmallInput, + ) + }); + + c.bench_function(&format!("add-latency<{}>", type_name::()), |b| { + b.iter_batched( + || F::rand(), + |mut x| { + for _ in 0..100 { + x = x + x; + } + x + }, BatchSize::SmallInput, ) });