mirror of
https://github.com/arnaucube/poseidon-ark.git
synced 2026-01-11 08:21:31 +01:00
Add benchmarks (49x improvement with ff)
Tested on a Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz, with 16GB of RAM. - Old (using nnum-bigint): hash time: [5.9258 ms 5.9407 ms 5.9587 ms] - New (using ff): hash time: [120.12 us 121.08 us 122.30 us]
This commit is contained in:
@@ -12,3 +12,9 @@ readme = "README.md"
|
|||||||
ff = {package="ff_ce" , version="0.11", features = ["derive"]}
|
ff = {package="ff_ce" , version="0.11", features = ["derive"]}
|
||||||
rand = "0.4"
|
rand = "0.4"
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
criterion = "0.3"
|
||||||
|
|
||||||
|
[[bench]]
|
||||||
|
name = "bench_poseidon_hash"
|
||||||
|
harness = false
|
||||||
|
|||||||
@@ -7,3 +7,8 @@ Compatible with the Poseidon Go implementation done in https://github.com/iden3/
|
|||||||
|
|
||||||
## Warning
|
## Warning
|
||||||
Do not use in production
|
Do not use in production
|
||||||
|
|
||||||
|
## Benchmarks
|
||||||
|
```
|
||||||
|
hash time: [120.12 us 121.08 us 122.30 us]
|
||||||
|
```
|
||||||
|
|||||||
30
benches/bench_poseidon_hash.rs
Normal file
30
benches/bench_poseidon_hash.rs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||||
|
|
||||||
|
extern crate rand;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate ff;
|
||||||
|
use ff::*;
|
||||||
|
|
||||||
|
use poseidon_rs::Poseidon;
|
||||||
|
|
||||||
|
fn criterion_benchmark(c: &mut Criterion) {
|
||||||
|
let b1: poseidon_rs::Fr = poseidon_rs::Fr::from_str(
|
||||||
|
"12242166908188651009877250812424843524687801523336557272219921456462821518061",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let b2: poseidon_rs::Fr = poseidon_rs::Fr::from_str(
|
||||||
|
"12242166908188651009877250812424843524687801523336557272219921456462821518061",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let mut big_arr: Vec<poseidon_rs::Fr> = Vec::new();
|
||||||
|
big_arr.push(b1.clone());
|
||||||
|
big_arr.push(b2.clone());
|
||||||
|
let poseidon = Poseidon::new();
|
||||||
|
|
||||||
|
c.bench_function("hash", |b| {
|
||||||
|
b.iter(|| poseidon.hash(big_arr.clone()).unwrap())
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
criterion_group!(benches, criterion_benchmark);
|
||||||
|
criterion_main!(benches);
|
||||||
Reference in New Issue
Block a user