-
Notifications
You must be signed in to change notification settings - Fork 18
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
10 changed files
with
235 additions
and
279 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,128 +1,128 @@ | ||
// use ark_std::test_rng; | ||
// use criterion::{BatchSize, Criterion, black_box, criterion_group, criterion_main}; | ||
// use ff::Field; | ||
// use goldilocks::Goldilocks; | ||
// use plonky2::{ | ||
// field::{goldilocks_field::GoldilocksField, types::Sample}, | ||
// hash::{ | ||
// hash_types::HashOut, | ||
// hashing::PlonkyPermutation, | ||
// poseidon::{PoseidonHash as PlonkyPoseidonHash, PoseidonPermutation}, | ||
// }, | ||
// plonk::config::Hasher, | ||
// }; | ||
// use poseidon::{digest::Digest, poseidon_hash::PoseidonHash}; | ||
|
||
// fn random_plonky_2_goldy() -> GoldilocksField { | ||
// GoldilocksField::rand() | ||
// } | ||
|
||
// fn random_ceno_goldy() -> Goldilocks { | ||
// Goldilocks::random(&mut test_rng()) | ||
// } | ||
|
||
// fn random_ceno_hash() -> Digest<Goldilocks> { | ||
// Digest( | ||
// vec![Goldilocks::random(&mut test_rng()); 4] | ||
// .try_into() | ||
// .unwrap(), | ||
// ) | ||
// } | ||
|
||
// fn plonky_hash_single(a: GoldilocksField) { | ||
// let _result = black_box(PlonkyPoseidonHash::hash_or_noop(&[a])); | ||
// } | ||
|
||
// fn ceno_hash_single(a: Goldilocks) { | ||
// let _result = black_box(PoseidonHash::hash_or_noop(&[a])); | ||
// } | ||
|
||
// fn plonky_hash_2_to_1(left: HashOut<GoldilocksField>, right: HashOut<GoldilocksField>) { | ||
// let _result = black_box(PlonkyPoseidonHash::two_to_one(left, right)); | ||
// } | ||
|
||
// fn ceno_hash_2_to_1(left: &Digest<Goldilocks>, right: &Digest<Goldilocks>) { | ||
// let _result = black_box(PoseidonHash::two_to_one(left, right)); | ||
// } | ||
|
||
// fn plonky_hash_many_to_1(values: &[GoldilocksField]) { | ||
// let _result = black_box(PlonkyPoseidonHash::hash_or_noop(values)); | ||
// } | ||
|
||
// fn ceno_hash_many_to_1(values: &[Goldilocks]) { | ||
// let _result = black_box(PoseidonHash::hash_or_noop(values)); | ||
// } | ||
|
||
// pub fn hashing_benchmark(c: &mut Criterion) { | ||
// c.bench_function("plonky hash single", |bencher| { | ||
// bencher.iter_batched( | ||
// random_plonky_2_goldy, | ||
// plonky_hash_single, | ||
// BatchSize::SmallInput, | ||
// ) | ||
// }); | ||
|
||
// c.bench_function("plonky hash 2 to 1", |bencher| { | ||
// bencher.iter_batched( | ||
// || { | ||
// ( | ||
// HashOut::<GoldilocksField>::rand(), | ||
// HashOut::<GoldilocksField>::rand(), | ||
// ) | ||
// }, | ||
// |(left, right)| plonky_hash_2_to_1(left, right), | ||
// BatchSize::SmallInput, | ||
// ) | ||
// }); | ||
|
||
// c.bench_function("plonky hash 60 to 1", |bencher| { | ||
// bencher.iter_batched( | ||
// || GoldilocksField::rand_vec(60), | ||
// |sixty_elems| plonky_hash_many_to_1(sixty_elems.as_slice()), | ||
// BatchSize::SmallInput, | ||
// ) | ||
// }); | ||
|
||
// c.bench_function("ceno hash single", |bencher| { | ||
// bencher.iter_batched(random_ceno_goldy, ceno_hash_single, BatchSize::SmallInput) | ||
// }); | ||
|
||
// c.bench_function("ceno hash 2 to 1", |bencher| { | ||
// bencher.iter_batched( | ||
// || (random_ceno_hash(), random_ceno_hash()), | ||
// |(left, right)| ceno_hash_2_to_1(&left, &right), | ||
// BatchSize::SmallInput, | ||
// ) | ||
// }); | ||
|
||
// c.bench_function("ceno hash 60 to 1", |bencher| { | ||
// bencher.iter_batched( | ||
// || { | ||
// (0..60) | ||
// .map(|_| Goldilocks::random(&mut test_rng())) | ||
// .collect::<Vec<_>>() | ||
// }, | ||
// |values| ceno_hash_many_to_1(values.as_slice()), | ||
// BatchSize::SmallInput, | ||
// ) | ||
// }); | ||
// } | ||
|
||
// // bench permutation | ||
// pub fn permutation_benchmark(c: &mut Criterion) { | ||
// let mut plonky_permutation = PoseidonPermutation::new(core::iter::repeat(GoldilocksField(0))); | ||
// let mut ceno_permutation = poseidon::poseidon_permutation::PoseidonPermutation::new( | ||
// core::iter::repeat(Goldilocks::ZERO), | ||
// ); | ||
|
||
// c.bench_function("plonky permute", |bencher| { | ||
// bencher.iter(|| plonky_permutation.permute()) | ||
// }); | ||
|
||
// c.bench_function("ceno permute", |bencher| { | ||
// bencher.iter(|| ceno_permutation.permute()) | ||
// }); | ||
// } | ||
|
||
// criterion_group!(benches, permutation_benchmark, hashing_benchmark); | ||
// criterion_main!(benches); | ||
use ark_std::test_rng; | ||
use criterion::{BatchSize, Criterion, black_box, criterion_group, criterion_main}; | ||
use ff::Field; | ||
use goldilocks::Goldilocks; | ||
use plonky2::{ | ||
field::{goldilocks_field::GoldilocksField, types::Sample}, | ||
hash::{ | ||
hash_types::HashOut, | ||
hashing::PlonkyPermutation, | ||
poseidon::{PoseidonHash as PlonkyPoseidonHash, PoseidonPermutation}, | ||
}, | ||
plonk::config::Hasher, | ||
}; | ||
use poseidon::{digest::Digest, poseidon_hash::PoseidonHash}; | ||
|
||
fn random_plonky_2_goldy() -> GoldilocksField { | ||
GoldilocksField::rand() | ||
} | ||
|
||
fn random_ceno_goldy() -> Goldilocks { | ||
Goldilocks::random(&mut test_rng()) | ||
} | ||
|
||
fn random_ceno_hash() -> Digest<Goldilocks> { | ||
Digest( | ||
vec![Goldilocks::random(&mut test_rng()); 4] | ||
.try_into() | ||
.unwrap(), | ||
) | ||
} | ||
|
||
fn plonky_hash_single(a: GoldilocksField) { | ||
let _result = black_box(PlonkyPoseidonHash::hash_or_noop(&[a])); | ||
} | ||
|
||
fn ceno_hash_single(a: Goldilocks) { | ||
let _result = black_box(PoseidonHash::hash_or_noop(&[a])); | ||
} | ||
|
||
fn plonky_hash_2_to_1(left: HashOut<GoldilocksField>, right: HashOut<GoldilocksField>) { | ||
let _result = black_box(PlonkyPoseidonHash::two_to_one(left, right)); | ||
} | ||
|
||
fn ceno_hash_2_to_1(left: &Digest<Goldilocks>, right: &Digest<Goldilocks>) { | ||
let _result = black_box(PoseidonHash::two_to_one(left, right)); | ||
} | ||
|
||
fn plonky_hash_many_to_1(values: &[GoldilocksField]) { | ||
let _result = black_box(PlonkyPoseidonHash::hash_or_noop(values)); | ||
} | ||
|
||
fn ceno_hash_many_to_1(values: &[Goldilocks]) { | ||
let _result = black_box(PoseidonHash::hash_or_noop(values)); | ||
} | ||
|
||
pub fn hashing_benchmark(c: &mut Criterion) { | ||
c.bench_function("plonky hash single", |bencher| { | ||
bencher.iter_batched( | ||
random_plonky_2_goldy, | ||
plonky_hash_single, | ||
BatchSize::SmallInput, | ||
) | ||
}); | ||
|
||
c.bench_function("plonky hash 2 to 1", |bencher| { | ||
bencher.iter_batched( | ||
|| { | ||
( | ||
HashOut::<GoldilocksField>::rand(), | ||
HashOut::<GoldilocksField>::rand(), | ||
) | ||
}, | ||
|(left, right)| plonky_hash_2_to_1(left, right), | ||
BatchSize::SmallInput, | ||
) | ||
}); | ||
|
||
c.bench_function("plonky hash 60 to 1", |bencher| { | ||
bencher.iter_batched( | ||
|| GoldilocksField::rand_vec(60), | ||
|sixty_elems| plonky_hash_many_to_1(sixty_elems.as_slice()), | ||
BatchSize::SmallInput, | ||
) | ||
}); | ||
|
||
c.bench_function("ceno hash single", |bencher| { | ||
bencher.iter_batched(random_ceno_goldy, ceno_hash_single, BatchSize::SmallInput) | ||
}); | ||
|
||
c.bench_function("ceno hash 2 to 1", |bencher| { | ||
bencher.iter_batched( | ||
|| (random_ceno_hash(), random_ceno_hash()), | ||
|(left, right)| ceno_hash_2_to_1(&left, &right), | ||
BatchSize::SmallInput, | ||
) | ||
}); | ||
|
||
c.bench_function("ceno hash 60 to 1", |bencher| { | ||
bencher.iter_batched( | ||
|| { | ||
(0..60) | ||
.map(|_| Goldilocks::random(&mut test_rng())) | ||
.collect::<Vec<_>>() | ||
}, | ||
|values| ceno_hash_many_to_1(values.as_slice()), | ||
BatchSize::SmallInput, | ||
) | ||
}); | ||
} | ||
|
||
// bench permutation | ||
pub fn permutation_benchmark(c: &mut Criterion) { | ||
let mut plonky_permutation = PoseidonPermutation::new(core::iter::repeat(GoldilocksField(0))); | ||
let mut ceno_permutation = poseidon::poseidon_permutation::PoseidonPermutation::new( | ||
core::iter::repeat(Goldilocks::ZERO), | ||
); | ||
|
||
c.bench_function("plonky permute", |bencher| { | ||
bencher.iter(|| plonky_permutation.permute()) | ||
}); | ||
|
||
c.bench_function("ceno permute", |bencher| { | ||
bencher.iter(|| ceno_permutation.permute()) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, permutation_benchmark, hashing_benchmark); | ||
criterion_main!(benches); |
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
Oops, something went wrong.