Skip to content

Commit

Permalink
[WIP] Speed test for iterative vs. recursive FFT
Browse files Browse the repository at this point in the history
  • Loading branch information
cjpatton committed Apr 3, 2021
1 parent 4351257 commit d440206
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ thiserror = "1.0"

[dev-dependencies]
assert_matches = "1.5.0"
criterion = "0.3"
modinverse = "0.1.0"
num-bigint = "0.4.0"

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

[[example]]
name = "sum"
57 changes: 57 additions & 0 deletions benches/fft.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: MPL-2.0

use criterion::{criterion_group, criterion_main, Criterion};
use prio::fft;
use prio::finite_field::{Field, FieldElement};
use prio::polynomial;

pub fn fft(c: &mut Criterion) {
let test_sizes = [16, 256, 1024, 4096];
for size in test_sizes.iter() {
let mut rng = rand::thread_rng();
let mut inp = vec![Field::zero(); *size];
let mut outp = vec![Field::zero(); *size];
for i in 0..*size {
inp[i] = Field::rand(&mut rng);
}

// Test recursive FFT, including auxiliary data computation.
c.bench_function(&format!("recursive/{}", *size), |b| {
b.iter(|| {
let mut mem = polynomial::PolyAuxMemory::new(*size / 2);
polynomial::poly_fft(
&mut outp,
&inp,
&mem.roots_2n,
*size,
false,
&mut mem.fft_memory,
)
})
});

// Test recursive FFT, but amortize auxiliary data computation across all of the
// invocations of the call.
let mut mem = polynomial::PolyAuxMemory::new(*size / 2);
c.bench_function(&format!("recursive/{} (amortized)", *size), |b| {
b.iter(|| {
polynomial::poly_fft(
&mut outp,
&inp,
&mem.roots_2n,
*size,
false,
&mut mem.fft_memory,
)
})
});

// Test iteratigve FFT.
c.bench_function(&format!("iterative/{}", *size), |b| {
b.iter(|| fft::discrete_fourier_transform::<Field>(&mut outp, &inp))
});
}
}

criterion_group!(benches, fft);
criterion_main!(benches);
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub mod encrypt;
pub mod fft;
pub mod finite_field;
mod fp;
mod polynomial;
pub mod polynomial;
mod prng;
pub mod server;
pub mod util;
Expand Down

0 comments on commit d440206

Please sign in to comment.