Benchmark transpose (#190)

* Benchmark transpose

* fmt
This commit is contained in:
Daniel Lubarov 2021-08-18 09:43:19 -07:00 committed by GitHub
parent d497c10858
commit d41924dad3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 1 deletions

View File

@ -36,6 +36,10 @@ harness = false
name = "ffts"
harness = false
[[bench]]
name = "transpose"
harness = false
[profile.release]
opt-level = 3
#lto = "fat"

26
benches/transpose.rs Normal file
View File

@ -0,0 +1,26 @@
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use plonky2::field::crandall_field::CrandallField;
use plonky2::field::field_types::Field;
use plonky2::util::transpose;
fn criterion_benchmark(c: &mut Criterion) {
type F = CrandallField;
// In practice, for the matrices we care about, each row is associated with a polynomial of
// degree 2^13, and has been low-degree extended to a length of 2^16.
const WIDTH: usize = 1 << 16;
let mut group = c.benchmark_group("transpose");
// We have matrices with various numbers of polynomials. For example, the witness matrix
// involves 100+ polynomials.
for height in [5, 50, 100, 150] {
group.bench_with_input(BenchmarkId::from_parameter(height), &height, |b, _| {
let matrix = (0..height).map(|_| F::rand_vec(WIDTH)).collect::<Vec<_>>();
b.iter(|| transpose(&matrix));
});
}
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);

View File

@ -35,7 +35,7 @@ pub(crate) fn transpose_poly_values<F: Field>(polys: Vec<PolynomialValues<F>>) -
transpose(&poly_values)
}
pub(crate) fn transpose<F: Field>(matrix: &[Vec<F>]) -> Vec<Vec<F>> {
pub fn transpose<F: Field>(matrix: &[Vec<F>]) -> Vec<Vec<F>> {
let l = matrix.len();
let w = matrix[0].len();
let mut transposed = vec![vec![F::ZERO; l]; w];