Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_o3db_sync/benches/hash.rs

1.0 KiB, 5 runs

created by r1870400018:657, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1// To switch to nightly to run these benchmarks:
2// > rustup override set nightly
3// > clear;clear;cargo bench
4// To switch back to stable:
5// > rustup override set stable
6//
7// Run this with
8// > cargo bench
9#![feature(test)]
10extern crate test;
11
12use oxedyne_fe2o3_core::prelude::*;
13use oxedyne_fe2o3_crypto::{
14 hash::HashScheme,
15};
16
17use test::Bencher;
18
19const INPUT_LEN: usize = 32;
20const CRYPTO_HASH_LEN: usize = 32;
21
22fn gen_input() -> [u8; INPUT_LEN] {
23 [42u8; INPUT_LEN]
24}
25
26#[bench]
27fn bench_seahash(b: &mut Bencher) -> Result<()> {
28 let input = gen_input();
29 b.iter(|| {
30 test::black_box({
31 let hash = seahash::hash(&input);
32 hash.to_be_bytes();
33 });
34 });
35 Ok(())
36}
37
38#[bench]
39fn bench_sha_256(b: &mut Bencher) -> Result<()> {
40 let input = gen_input();
41 let mut output = [0u8; CRYPTO_HASH_LEN];
42 b.iter(|| {
43 test::black_box({
44 let mut hasher = HashScheme::new_sha3_256();
45 hasher.update(&input);
46 hasher.finalize(&mut output);
47 });
48 });
49 Ok(())
50}