-
Notifications
You must be signed in to change notification settings - Fork 1
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
19 changed files
with
532 additions
and
29 deletions.
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
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,234 @@ | ||
#![allow(dead_code)] | ||
use criterion::{black_box, Criterion}; | ||
use crypto_bigint::rand_core::OsRng; | ||
use crypto_bigint::U256; | ||
use sylow::{FieldExtensionTrait, Fp, Fp12, Fp2, Fp6}; | ||
pub mod fp { | ||
use super::*; | ||
const A: Fp = Fp::THREE; | ||
const B: Fp = Fp::FOUR; | ||
|
||
pub fn test_fp_multiplication(c: &mut Criterion) { | ||
c.bench_function("test_fp_multiplication", |b| { | ||
b.iter(|| black_box(A) * black_box(B)) | ||
}); | ||
} | ||
pub fn test_fp_addition(c: &mut Criterion) { | ||
c.bench_function("test_fp_addition", |b| { | ||
b.iter(|| black_box(A) + black_box(B)) | ||
}); | ||
} | ||
pub fn test_fp_subtraction(c: &mut Criterion) { | ||
c.bench_function("test_fp_subtraction", |b| { | ||
b.iter(|| black_box(A) - black_box(B)) | ||
}); | ||
} | ||
pub fn test_fp_division(c: &mut Criterion) { | ||
c.bench_function("test_fp_division", |b| { | ||
b.iter(|| black_box(A) / black_box(B)) | ||
}); | ||
} | ||
pub fn test_fp_random(c: &mut Criterion) { | ||
let mut rng = OsRng; | ||
c.bench_function("test_fp_random", |b| { | ||
b.iter(|| <Fp as FieldExtensionTrait<1, 1>>::rand(&mut rng)) | ||
}); | ||
} | ||
pub fn test_fp_new(c: &mut Criterion) { | ||
c.bench_function("test_fp_new", |b| { | ||
b.iter(|| Fp::new(U256::from_words([1, 2, 3, 4]))) | ||
}); | ||
} | ||
} | ||
|
||
pub mod fp2 { | ||
use super::*; | ||
const A: Fp2 = Fp2::new(&[Fp::FOUR, Fp::NINE]); | ||
const B: Fp2 = Fp2::new(&[Fp::NINE, Fp::FOUR]); | ||
|
||
pub fn test_fp2_multiplication(c: &mut Criterion) { | ||
c.bench_function("test_fp2_multiplication", |b| { | ||
b.iter(|| black_box(A) * black_box(B)) | ||
}); | ||
} | ||
pub fn test_fp2_addition(c: &mut Criterion) { | ||
c.bench_function("test_fp2_addition", |b| { | ||
b.iter(|| black_box(A) + black_box(B)) | ||
}); | ||
} | ||
pub fn test_fp2_subtraction(c: &mut Criterion) { | ||
c.bench_function("test_fp2_subtraction", |b| { | ||
b.iter(|| black_box(A) - black_box(B)) | ||
}); | ||
} | ||
pub fn test_fp2_division(c: &mut Criterion) { | ||
c.bench_function("test_fp2_division", |b| { | ||
b.iter(|| black_box(A) / black_box(B)) | ||
}); | ||
} | ||
pub fn test_fp2_random(c: &mut Criterion) { | ||
let mut rng = OsRng; | ||
c.bench_function("test_fp2_random", |b| { | ||
b.iter(|| <Fp2 as FieldExtensionTrait<2, 2>>::rand(&mut rng)) | ||
}); | ||
} | ||
pub fn test_fp2_new(c: &mut Criterion) { | ||
c.bench_function("test_fp2_new", |b| { | ||
b.iter(|| { | ||
Fp2::new(&[ | ||
Fp::new(U256::from_words([1, 2, 3, 4])), | ||
Fp::new(U256::from_words([1, 2, 3, 4])), | ||
]) | ||
}) | ||
}); | ||
} | ||
} | ||
pub mod fp6 { | ||
use super::*; | ||
const A: Fp6 = Fp6::new(&[ | ||
Fp2::new(&[Fp::FOUR, Fp::NINE]), | ||
Fp2::new(&[Fp::FOUR, Fp::NINE]), | ||
Fp2::new(&[Fp::FOUR, Fp::NINE]), | ||
]); | ||
|
||
const B: Fp6 = Fp6::new(&[ | ||
Fp2::new(&[Fp::NINE, Fp::FOUR]), | ||
Fp2::new(&[Fp::NINE, Fp::FOUR]), | ||
Fp2::new(&[Fp::NINE, Fp::FOUR]), | ||
]); | ||
|
||
pub fn test_fp6_multiplication(c: &mut Criterion) { | ||
c.bench_function("test_fp6_multiplication", |b| { | ||
b.iter(|| black_box(A) * black_box(B)) | ||
}); | ||
} | ||
pub fn test_fp6_addition(c: &mut Criterion) { | ||
c.bench_function("test_fp6_addition", |b| { | ||
b.iter(|| black_box(A) + black_box(B)) | ||
}); | ||
} | ||
pub fn test_fp6_subtraction(c: &mut Criterion) { | ||
c.bench_function("test_fp6_subtraction", |b| { | ||
b.iter(|| black_box(A) - black_box(B)) | ||
}); | ||
} | ||
pub fn test_fp6_division(c: &mut Criterion) { | ||
c.bench_function("test_fp6_division", |b| { | ||
b.iter(|| black_box(A) / black_box(B)) | ||
}); | ||
} | ||
pub fn test_fp6_random(c: &mut Criterion) { | ||
let mut rng = OsRng; | ||
c.bench_function("test_fp6_random", |b| { | ||
b.iter(|| <Fp6 as FieldExtensionTrait<6, 3>>::rand(&mut rng)) | ||
}); | ||
} | ||
pub fn test_fp6_new(c: &mut Criterion) { | ||
c.bench_function("test_fp6_new", |b| { | ||
b.iter(|| { | ||
Fp6::new(&[ | ||
Fp2::new(&[ | ||
Fp::new(U256::from_words([1, 2, 3, 4])), | ||
Fp::new(U256::from_words([1, 2, 3, 4])), | ||
]), | ||
Fp2::new(&[ | ||
Fp::new(U256::from_words([1, 2, 3, 4])), | ||
Fp::new(U256::from_words([1, 2, 3, 4])), | ||
]), | ||
Fp2::new(&[ | ||
Fp::new(U256::from_words([1, 2, 3, 4])), | ||
Fp::new(U256::from_words([1, 2, 3, 4])), | ||
]), | ||
]) | ||
}) | ||
}); | ||
} | ||
} | ||
pub mod fp12 { | ||
use super::*; | ||
const A: Fp12 = Fp12::new(&[ | ||
Fp6::new(&[ | ||
Fp2::new(&[Fp::FOUR, Fp::NINE]), | ||
Fp2::new(&[Fp::FOUR, Fp::NINE]), | ||
Fp2::new(&[Fp::FOUR, Fp::NINE]), | ||
]), | ||
Fp6::new(&[ | ||
Fp2::new(&[Fp::FOUR, Fp::NINE]), | ||
Fp2::new(&[Fp::FOUR, Fp::NINE]), | ||
Fp2::new(&[Fp::FOUR, Fp::NINE]), | ||
]), | ||
]); | ||
|
||
const B: Fp12 = Fp12::new(&[ | ||
Fp6::new(&[ | ||
Fp2::new(&[Fp::NINE, Fp::FOUR]), | ||
Fp2::new(&[Fp::NINE, Fp::FOUR]), | ||
Fp2::new(&[Fp::NINE, Fp::FOUR]), | ||
]), | ||
Fp6::new(&[ | ||
Fp2::new(&[Fp::NINE, Fp::FOUR]), | ||
Fp2::new(&[Fp::NINE, Fp::FOUR]), | ||
Fp2::new(&[Fp::NINE, Fp::FOUR]), | ||
]), | ||
]); | ||
pub fn test_fp12_multiplication(c: &mut Criterion) { | ||
c.bench_function("test_fp12_multiplication", |b| { | ||
b.iter(|| black_box(A) * black_box(B)) | ||
}); | ||
} | ||
pub fn test_fp12_addition(c: &mut Criterion) { | ||
c.bench_function("test_fp12_addition", |b| { | ||
b.iter(|| black_box(A) + black_box(B)) | ||
}); | ||
} | ||
pub fn test_fp12_subtraction(c: &mut Criterion) { | ||
c.bench_function("test_fp12_subtraction", |b| { | ||
b.iter(|| black_box(A) - black_box(B)) | ||
}); | ||
} | ||
pub fn test_fp12_division(c: &mut Criterion) { | ||
c.bench_function("test_fp12_division", |b| { | ||
b.iter(|| black_box(A) / black_box(B)) | ||
}); | ||
} | ||
pub fn test_fp12_random(c: &mut Criterion) { | ||
let mut rng = OsRng; | ||
c.bench_function("test_fp12_random", |b| b.iter(|| Fp12::rand(&mut rng))); | ||
} | ||
pub fn test_fp12_new(c: &mut Criterion) { | ||
c.bench_function("test_fp12_new", |b| { | ||
b.iter(|| { | ||
Fp12::new(&[ | ||
Fp6::new(&[ | ||
Fp2::new(&[ | ||
Fp::new(U256::from_words([1, 2, 3, 4])), | ||
Fp::new(U256::from_words([1, 2, 3, 4])), | ||
]), | ||
Fp2::new(&[ | ||
Fp::new(U256::from_words([1, 2, 3, 4])), | ||
Fp::new(U256::from_words([1, 2, 3, 4])), | ||
]), | ||
Fp2::new(&[ | ||
Fp::new(U256::from_words([1, 2, 3, 4])), | ||
Fp::new(U256::from_words([1, 2, 3, 4])), | ||
]), | ||
]), | ||
Fp6::new(&[ | ||
Fp2::new(&[ | ||
Fp::new(U256::from_words([1, 2, 3, 4])), | ||
Fp::new(U256::from_words([1, 2, 3, 4])), | ||
]), | ||
Fp2::new(&[ | ||
Fp::new(U256::from_words([1, 2, 3, 4])), | ||
Fp::new(U256::from_words([1, 2, 3, 4])), | ||
]), | ||
Fp2::new(&[ | ||
Fp::new(U256::from_words([1, 2, 3, 4])), | ||
Fp::new(U256::from_words([1, 2, 3, 4])), | ||
]), | ||
]), | ||
]) | ||
}) | ||
}); | ||
} | ||
} |
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,112 @@ | ||
#![allow(dead_code)] | ||
use criterion::{black_box, Criterion}; | ||
use sylow::{Fp, G1Affine, G1Projective, G2Affine, G2Projective, GroupTrait}; | ||
|
||
pub mod g1 { | ||
use super::*; | ||
use sylow::Fp; | ||
|
||
const KNOWN_VALUES: [Fp; 3] = [Fp::ONE, Fp::TWO, Fp::ONE]; | ||
|
||
pub fn test_g1affine_conversion_to_g1projective(c: &mut Criterion) { | ||
let generator = G1Affine::generator(); | ||
c.bench_function("g1affine_conversion_to_g1projective", |b| { | ||
b.iter(|| G1Projective::from(black_box(generator))) | ||
}); | ||
} | ||
pub fn test_g1projective_generation(c: &mut Criterion) { | ||
c.bench_function("test_g1projective_generation", |b| { | ||
b.iter(|| { | ||
G1Projective::new(black_box(KNOWN_VALUES)).expect("Failed to create G1Projective") | ||
}) | ||
}); | ||
} | ||
pub fn test_g1projective_addition(c: &mut Criterion) { | ||
let a = G1Projective::generator(); | ||
c.bench_function("test_g1projective_addition", |b| { | ||
b.iter(|| black_box(a) + black_box(a)) | ||
}); | ||
} | ||
pub fn test_g1projective_multiplication(c: &mut Criterion) { | ||
let g1_projective = G1Projective::generator(); | ||
const SCALAR: Fp = Fp::THREE; | ||
c.bench_function("test_g1projective_multiplication", |b| { | ||
b.iter(|| black_box(g1_projective) * black_box(SCALAR)) | ||
}); | ||
} | ||
pub fn test_g1projective_conversion_to_g1affine(c: &mut Criterion) { | ||
let generator = G1Projective::generator(); | ||
c.bench_function("g1projective_conversion_to_g1affine", |b| { | ||
b.iter(|| G1Affine::from(black_box(generator))) | ||
}); | ||
} | ||
} | ||
|
||
pub mod g2 { | ||
use super::*; | ||
use crypto_bigint::U256; | ||
use sylow::Fp2; | ||
|
||
const KNOWN_X: Fp2 = Fp2::new(&[ | ||
Fp::new(U256::from_words([ | ||
15176525146662381588, | ||
16999198464856720888, | ||
10551491725746096164, | ||
2109507925758354620, | ||
])), | ||
Fp::new(U256::from_words([ | ||
5829542572658843162, | ||
6956048341656855305, | ||
457351042342223481, | ||
213802418293478404, | ||
])), | ||
]); | ||
const KNOWN_Y: Fp2 = Fp2::new(&[ | ||
Fp::new(U256::from_words([ | ||
16717123787957323851, | ||
9581483432139821434, | ||
7173403850490595536, | ||
650007998934857427, | ||
])), | ||
Fp::new(U256::from_words([ | ||
5081543861758110462, | ||
8687473586797606316, | ||
15555792616844701404, | ||
3266271495335422485, | ||
])), | ||
]); | ||
const KNOWN_Z: Fp2 = Fp2::new(&[Fp::ONE, Fp::ZERO]); | ||
pub fn test_g2affine_conversion_to_g2projective(c: &mut Criterion) { | ||
let generator = G2Affine::generator(); | ||
c.bench_function("g2affine_conversion_to_g2projective", |b| { | ||
b.iter(|| G2Projective::from(black_box(generator))) | ||
}); | ||
} | ||
pub fn test_g2projective_valid_generation(c: &mut Criterion) { | ||
c.bench_function("test_g2projective_generation", |b| { | ||
b.iter(|| { | ||
G2Projective::new(black_box([KNOWN_X, KNOWN_Y, KNOWN_Z])) | ||
.expect("Failed to create G2Projective") | ||
}) | ||
}); | ||
} | ||
pub fn test_g2projective_addition(c: &mut Criterion) { | ||
let a = G2Projective::generator(); | ||
c.bench_function("test_g2projective_addition", |b| { | ||
b.iter(|| black_box(a) + black_box(a)) | ||
}); | ||
} | ||
pub fn test_g2projective_multiplication(c: &mut Criterion) { | ||
let g2_projective = G2Projective::generator(); | ||
const SCALAR: Fp = Fp::THREE; | ||
c.bench_function("test_g2projective_multiplication", |b| { | ||
b.iter(|| black_box(g2_projective) * black_box(SCALAR)) | ||
}); | ||
} | ||
pub fn test_g2projective_conversion_to_g2affine(c: &mut Criterion) { | ||
let generator = G2Projective::generator(); | ||
c.bench_function("g2projective_conversion_to_g2affine", |b| { | ||
b.iter(|| G2Affine::from(black_box(generator))) | ||
}); | ||
} | ||
} |
Oops, something went wrong.