-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Benchmarks | ||
|
||
## Table of Contents | ||
|
||
- [Overview](#overview) | ||
- [Benchmark Results](#benchmark-results) | ||
- [Polynomial Multiplication Benchmarks](#polynomial-multiplication-benchmarks) | ||
|
||
## Overview | ||
|
||
This benchmark comparison report shows the difference in performance between parallel, NTT-based and serial, brute-force | ||
polynomial multiplication algorithms. Each row entry in the first table is an n-degree forward NTT and each row entry in the second table represents an n-degree polynomial multiplication. | ||
|
||
Computer Stats: | ||
|
||
``` | ||
CPU(s): 16 | ||
Thread(s) per core: 2 | ||
Core(s) per socket: 8 | ||
Socket(s): 1 | ||
``` | ||
|
||
## Benchmark Results | ||
|
||
### Polynomial Multiplication Benchmarks | ||
|
||
| | `NTT-Based` | `Concrete-NTT` | | ||
|:------------|:--------------------------|:------------------------------------ | | ||
| **`64`** | `982.22 us` (✅ **1.00x**) | `84.31 ns` (🚀 **11650.05x faster**) | | ||
| **`128`** | `1.18 ms` (✅ **1.00x**) | `149.42 ns` (🚀 **7901.64x faster**) | | ||
| **`256`** | `2.03 ms` (✅ **1.00x**) | `286.35 ns` (🚀 **7091.84x faster**) | | ||
| **`512`** | `2.75 ms` (✅ **1.00x**) | `600.13 ns` (🚀 **4580.51x faster**) | | ||
| **`1024`** | `4.99 ms` (✅ **1.00x**) | `1.32 us` (🚀 **3779.10x faster**) | | ||
| **`2048`** | `9.42 ms` (✅ **1.00x**) | `2.74 us` (🚀 **3434.03x faster**) | | ||
| **`4096`** | `18.04 ms` (✅ **1.00x**) | `5.84 us` (🚀 **3089.55x faster**) | | ||
| **`8192`** | `35.30 ms` (✅ **1.00x**) | `12.27 us` (🚀 **2877.03x faster**) | | ||
| **`16384`** | `72.15 ms` (✅ **1.00x**) | `25.50 us` (🚀 **2829.18x faster**) | | ||
| **`32768`** | `155.51 ms` (✅ **1.00x**) | `53.88 us` (🚀 **2886.10x faster**) | | ||
|
||
--- | ||
Made with [criterion-table](https://github.com/nu11ptr/criterion-table) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use concrete_ntt::prime32::Plan; | ||
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion}; | ||
use fast_ntt::{ | ||
ntt::{forward, working_modulus, Constants}, | ||
numbers::BigInt, | ||
polynomial::{fast_mul, mul_brute, Polynomial, PolynomialFieldElement, PolynomialTrait}, | ||
}; | ||
use itertools::Itertools; | ||
|
||
const deg: usize = 16; | ||
|
||
fn bench_mul<T: PolynomialFieldElement>(x: usize, c: &Constants<T>) { | ||
let ONE = T::from(1); | ||
let a = Polynomial::new(vec![0; x].iter().map(|_| ONE).collect_vec()); | ||
let b = Polynomial::new(vec![0; x].iter().map(|_| ONE).collect_vec()); | ||
let _ = fast_mul(a, b, c); | ||
} | ||
|
||
fn bench_concrete<T: PolynomialFieldElement>(x: usize, plan: &Plan) { | ||
let data = vec![1; x]; | ||
|
||
let mut transformed_fwd = data; | ||
plan.fwd(&mut transformed_fwd); | ||
} | ||
|
||
fn criterion_benchmark(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("Polynomial Multiplication Benchmarks"); | ||
|
||
(6..deg).for_each(|n| { | ||
let id = BenchmarkId::new("NTT-Based", 1 << n); | ||
let N = BigInt::from((2 * n).next_power_of_two()); | ||
let M = N << 1 + 1; | ||
let c = working_modulus(N, M); | ||
group.bench_with_input(id, &n, |b, n| { | ||
b.iter(|| bench_mul(black_box(1 << n), black_box(&c))) | ||
}); | ||
|
||
let id = BenchmarkId::new("Concrete-NTT", 1 << n); | ||
|
||
let N = (1 << n); | ||
let p = 1062862849; | ||
let plan = Plan::try_new(N, p).unwrap(); | ||
group.bench_with_input(id, &n, |b, n| { | ||
b.iter(|| bench_concrete::<BigInt>(black_box(1 << n), black_box(&plan))) | ||
}); | ||
}); | ||
} | ||
|
||
criterion_group! { | ||
name = benches; | ||
config = Criterion::default().sample_size(10); | ||
targets = criterion_benchmark | ||
} | ||
criterion_main!(benches); |