// Copyright 2020 Parity Technologies // // Licensed under the Apache License, Version 2.0 or the MIT license // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. use criterion::{black_box, criterion_group, criterion_main, Criterion}; use tetsy_keccak_hash::keccak; criterion_group!(keccak_256, keccak_256_with_empty_input, keccak_256_with_typical_input, keccak_256_with_large_input,); criterion_main!(keccak_256); pub fn keccak_256_with_empty_input(c: &mut Criterion) { let empty = [0u8; 0]; c.bench_function("keccak_256_with_empty_input", |b| { b.iter(|| { let _out = keccak(black_box(empty)); }) }); } pub fn keccak_256_with_typical_input(c: &mut Criterion) { let mut data: Vec = From::from("some medium length string with important information"); let len = data.len(); let mut group = c.benchmark_group("keccak_256_with_typical_input"); group.bench_function("regular", |b| { b.iter(|| { let _out = keccak(black_box(&data)); }) }); group.bench_function("inplace", |b| { b.iter(|| { tetsy_keccak_hash::keccak256(black_box(&mut data[..])); }) }); group.bench_function("inplace_range", |b| { b.iter(|| { tetsy_keccak_hash::keccak256_range(black_box(&mut data[..]), 0..len); }) }); group.finish(); } pub fn keccak_256_with_large_input(c: &mut Criterion) { // 4096 chars let data: Vec = From::from("IGxcKBr1Qp7tuqtpSVhAbvt7UgWLEi7mCA6Wa185seLSIJLFS8K1aAFO9AwtO9b3n9SM3Qg136JMmy9Mj9gZ84IaUm8XioPtloabFDU5ZR1wvauJT6jNTkvBVBpUigIsyU7C1u3s99vKP64LpXqvo1hwItZKtISxmUAgzzjv5q14V4G9bkKAnmc4M5xixgLsDGZmnj6HcOMY3XRkWtxN3RscSKwPA0bfpgtz27ZVHplbXwloYRgRLpjRhZJc7sqO8RFnTHKasVkxVRcUoDBvWNJK27TbLvQQcfxETI2Q1H6c2cBAchi8unSiuxqy5rIvVxcl9rsmmRY4IXLEG9qKntUGbiIRLjEffIP9ODoWog0GbWLmMtfvtf24hWVwXz6Ap5oUAR0kLgb7HYIYrOwKjvfV25iEF7GW8cjhl8yowXx1zcgW4t6NJNqJlGzRKx8MvRWQXvHz8h8JxcHl7S64i6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Qu4C9crEAxSSiOJOfnL3DYIVOY4ipUkKFlF7Rp2q6gZazDvcUCp1cbcr7T7B4s22rXzjN7mHYWOyWuZGwlImeorY3aVKi7BaXbhgOFw6BUmIc1HeGFELHIEnPE9MwOjZam3LOm0rhBHlvJJZkXvJKmDUJrGlyqC5GtC5lDWLfXewyDWDqq7PY0atVQily5GWqib6wub6u6LZ3HZDNP8gK64Nf4kC259AE4V2hCohDnSsXAIoOkehwXyp6CkDT42NJb6sXHUv2N6cm292MiKA22PKWrwUGsan599KI2V67YRDfcfiB4ZHRDiSe62MBE0fGLIgXLIWw1xTWYbPQ9YAj3xovBvmewbJ1De4k6uS"); c.bench_function("keccak_256_with_large_input", |b| { b.iter(|| { let _out = keccak(black_box(&data)); }) }); }