// Copyright 2021 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 #![allow(deprecated)] use bee_crypto::ternary::sponge::{BatchHasher, CurlP81, CurlPRounds, Sponge, UnrolledCurlP81, BATCH_SIZE}; use bee_ternary::{T1B1Buf, T5B1Buf, TritBuf, TryteBuf}; use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; use crypto::hashes::ternary::curl_p::CurlP; fn batched_hasher_t5b1(input: &TritBuf) { let mut hasher = BatchHasher::new(input.len(), CurlPRounds::Rounds81); for _ in 0..BATCH_SIZE { hasher.add(input.clone()); } for _ in hasher.hash_batched() {} } fn regular_hasher_t5b1(input: &TritBuf) { let mut hasher = CurlP::new(); for _ in 0..BATCH_SIZE { hasher.digest(&input.encode::()); } } fn regular_hasher_t5b1_legacy(input: &TritBuf) { let mut hasher = CurlP81::new(); for _ in 0..BATCH_SIZE { hasher.digest(&input.encode::()).unwrap(); } } fn unrolled_hasher_t5b1(input: &TritBuf) { let mut hasher = UnrolledCurlP81::new(); for _ in 0..BATCH_SIZE { hasher.digest(&input.encode::()).unwrap(); } } fn bench_hasher(c: &mut Criterion) { let input_243 = "HHPELNTNJIOKLYDUW9NDULWPHCWFRPTDIUWLYUHQWWJVPAKKGKOAZFJPQJBLNDPALCVXGJLRBFSHATF9C"; let input_8019 = "AQUIC9VCKYJWSGMGHMPGRMHLLCKBOCMLOKMLXAMWSCBEDOWQS9HJBYWNABSUHARMZHQFOMKNBUEKB9YWC9UWQVWIDRFPNUF9QGFORSXLLK9MBVVHSRQMOWEJIKGNMKTKKZLXXKFMSVZDUMMWGYEAWPGXRHJZOYYVOYUFQDELKPTFTFXFGN9KUCLXPSVVX9PXCKEGWBWMMYWVWBXUTAAZZALALFVCJWFP9HKIVGVZSBZSESSIEGTPPLNJZIIXJRRYUREWVOGOCGWMSJUISJHIRNTNCUV9CHRLVFBMCQSVB9DLMPYSJIOBWVJIXEVQORQJHSQLUPNJFGSXAOULRMIIXGVNSPFGFZZTCVHRT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WFRNIWMVPSICVZSWBW9JMEVVDHQRJWOPVHRBDMNEGRCVNYRLKPHZLQMLVYYBFVUXAIXYRRLW99999999999999999999999999999999USHXKUSRF999999999K99999999RC999999999PTA9999999999999"; let input_243 = TryteBuf::try_from_str(input_243) .unwrap() .as_trits() .encode::(); let input_8019 = TryteBuf::try_from_str(input_8019) .unwrap() .as_trits() .encode::(); let mut group = c.benchmark_group("CurlP"); group.throughput(Throughput::Elements(BATCH_SIZE as u64)); for input in [input_243, input_8019].iter() { let length = input.len(); // Using T5B1 directly. group.bench_with_input( BenchmarkId::new("Batched", format!("{} T5B1", length)), input, |b, i| b.iter(|| batched_hasher_t5b1(i)), ); group.bench_with_input( BenchmarkId::new("Regular", format!("{} T5B1", length)), input, |b, i| b.iter(|| regular_hasher_t5b1(i)), ); group.bench_with_input( BenchmarkId::new("Regular (legacy)", format!("{} T5B1", length)), input, |b, i| b.iter(|| regular_hasher_t5b1_legacy(i)), ); group.bench_with_input( BenchmarkId::new("Unrolled", format!("{} T5B1", length)), input, |b, i| b.iter(|| unrolled_hasher_t5b1(i)), ); } group.finish(); } criterion_group!(benches, bench_hasher); criterion_main!(benches);