/ console / algorithms / benches / keccak.rs
keccak.rs
 1  // Copyright (c) 2019-2025 Alpha-Delta Network Inc.
 2  // This file is part of the deltavm library.
 3  
 4  // Licensed under the Apache License, Version 2.0 (the "License");
 5  // you may not use this file except in compliance with the License.
 6  // You may obtain a copy of the License at:
 7  
 8  // http://www.apache.org/licenses/LICENSE-2.0
 9  
10  // Unless required by applicable law or agreed to in writing, software
11  // distributed under the License is distributed on an "AS IS" BASIS,
12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  // See the License for the specific language governing permissions and
14  // limitations under the License.
15  
16  #[macro_use]
17  extern crate criterion;
18  
19  use deltavm_console_algorithms::{Keccak256, Keccak384, Keccak512};
20  use deltavm_console_types::prelude::*;
21  use deltavm_utilities::{TestRng, Uniform};
22  
23  use criterion::Criterion;
24  
25  fn keccak256(c: &mut Criterion) {
26      let rng = &mut TestRng::default();
27      let hash = Keccak256::default();
28  
29      let input = (0..256).map(|_| bool::rand(rng)).collect::<Vec<_>>();
30      c.bench_function(&format!("Keccak256 Hash - input size {}", input.len()), |b| b.iter(|| hash.hash(&input)));
31  }
32  
33  fn keccak384(c: &mut Criterion) {
34      let rng = &mut TestRng::default();
35      let hash = Keccak384::default();
36  
37      let input = (0..256).map(|_| bool::rand(rng)).collect::<Vec<_>>();
38      c.bench_function(&format!("Keccak384 Hash - input size {}", input.len()), |b| b.iter(|| hash.hash(&input)));
39  }
40  
41  fn keccak512(c: &mut Criterion) {
42      let rng = &mut TestRng::default();
43      let hash = Keccak512::default();
44  
45      let input = (0..256).map(|_| bool::rand(rng)).collect::<Vec<_>>();
46      c.bench_function(&format!("Keccak512 Hash - input size {}", input.len()), |b| b.iter(|| hash.hash(&input)));
47  }
48  
49  criterion_group! {
50      name = keccak;
51      config = Criterion::default().sample_size(1000);
52      targets = keccak256, keccak384, keccak512
53  }
54  
55  criterion_main!(keccak);