add benches/criterion/cuprate-cryptonight

This commit is contained in:
hinto.janai 2024-10-24 19:31:37 -04:00
parent 1cada331f0
commit d89840e53f
No known key found for this signature in database
GPG key ID: D47CE05FA175A499
6 changed files with 134 additions and 0 deletions

9
Cargo.lock generated
View file

@ -739,6 +739,15 @@ dependencies = [
name = "cuprate-constants" name = "cuprate-constants"
version = "0.1.0" version = "0.1.0"
[[package]]
name = "cuprate-criterion-cryptonight"
version = "0.0.0"
dependencies = [
"criterion",
"cuprate-cryptonight",
"function_name",
]
[[package]] [[package]]
name = "cuprate-criterion-example" name = "cuprate-criterion-example"
version = "0.0.0" version = "0.0.0"

View file

@ -9,6 +9,7 @@ members = [
"benches/benchmark/example", "benches/benchmark/example",
"benches/criterion/example", "benches/criterion/example",
"benches/criterion/cuprate-json-rpc", "benches/criterion/cuprate-json-rpc",
"benches/criterion/cuprate-cryptonight",
# Consensus # Consensus
"consensus", "consensus",
"consensus/fast-sync", "consensus/fast-sync",

View file

@ -0,0 +1,22 @@
[package]
name = "cuprate-criterion-cryptonight"
version = "0.0.0"
edition = "2021"
description = "Criterion benchmarking for cuprate-cryptonight"
license = "MIT"
authors = ["hinto-janai"]
repository = "https://github.com/Cuprate/cuprate/tree/main/benches/criterion/cuprate-cryptonight"
keywords = ["cuprate", "cryptonight", "criterion", "benchmark"]
[dependencies]
criterion = { workspace = true }
function_name = { workspace = true }
cuprate-cryptonight = { path = "../../../cryptonight" }
[[bench]]
name = "main"
harness = false
[lints]
workspace = true

View file

@ -0,0 +1,92 @@
//! Benchmarks for [`Response`].
#![allow(unused_attributes, unused_crate_dependencies, dropping_copy_types)]
use std::time::Duration;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use function_name::named;
use cuprate_cryptonight::{
cryptonight_hash_r, cryptonight_hash_v0, cryptonight_hash_v1, cryptonight_hash_v2,
};
criterion_group! {
name = benches;
// Criterion suggests that higher measurement time is required for these hash functions.
config = Criterion::default().measurement_time(Duration::from_secs(8));
targets =
r_8, r_64, r_512, r_4096, r_65536,
v0_8, v0_64, v0_512, v0_4096, v0_65536,
v1_8, v1_64, v1_512, v1_4096, v1_65536,
v2_8, v2_64, v2_512, v2_4096, v2_65536,
}
criterion_main!(benches);
/// Generate the benchmark functions for the cryptonight hash functions.
macro_rules! impl_hash_benchmark {
($(
// The actual hash function.
$hash_fn:ident {
// Inside these braces:
// - The name of the benchmark function
// - The input(s) to the hash function for that benchmark function
$(
$fn_name:ident => ($($input:expr),* $(,)?)
),* $(,)?
}
)*) => {
$(
$(
#[named]
fn $fn_name(c: &mut Criterion) {
c.bench_function(function_name!(), |b| {
b.iter(|| {
drop(
black_box(
$hash_fn(
$(black_box($input)),*
)
)
);
});
});
}
)*
)*
};
}
impl_hash_benchmark! {
cryptonight_hash_r {
r_8 => (&[3; 8], 500_000),
r_64 => (&[3; 64], 500_000),
r_512 => (&[3; 512], 500_000),
r_4096 => (&[3; 4096], 500_000),
r_65536 => (&[3; 65536], 500_000),
}
cryptonight_hash_v0 {
v0_8 => (&[3; 8]),
v0_64 => (&[3; 64]),
v0_512 => (&[3; 512]),
v0_4096 => (&[3; 4096]),
v0_65536 => (&[3; 65536]),
}
cryptonight_hash_v1 {
v1_8 => (&[3; 8]),
v1_64 => (&[3; 64]),
v1_512 => (&[3; 512]),
v1_4096 => (&[3; 4096]),
v1_65536 => (&[3; 65536]),
}
cryptonight_hash_v2 {
v2_8 => (&[3; 8]),
v2_64 => (&[3; 64]),
v2_512 => (&[3; 512]),
v2_4096 => (&[3; 4096]),
v2_65536 => (&[3; 65536]),
}
}

View file

@ -0,0 +1,8 @@
//! Benchmarks for `cuprate-cryptonight`.
#![allow(unused_crate_dependencies)]
mod hash;
criterion::criterion_main! {
hash::benches
}

View file

@ -0,0 +1,2 @@
//! Benchmark lib for `cuprate-cryptonight`.
#![allow(unused_crate_dependencies, reason = "used in benchmarks")]