mirror of
https://github.com/hinto-janai/cuprate.git
synced 2024-11-16 15:58:14 +00:00
add benches/criterion/cuprate-cryptonight
This commit is contained in:
parent
1cada331f0
commit
d89840e53f
6 changed files with 134 additions and 0 deletions
9
Cargo.lock
generated
9
Cargo.lock
generated
|
@ -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"
|
||||||
|
|
|
@ -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",
|
||||||
|
|
22
benches/criterion/cuprate-cryptonight/Cargo.toml
Normal file
22
benches/criterion/cuprate-cryptonight/Cargo.toml
Normal 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
|
92
benches/criterion/cuprate-cryptonight/benches/hash.rs
Normal file
92
benches/criterion/cuprate-cryptonight/benches/hash.rs
Normal 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]),
|
||||||
|
}
|
||||||
|
}
|
8
benches/criterion/cuprate-cryptonight/benches/main.rs
Normal file
8
benches/criterion/cuprate-cryptonight/benches/main.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
//! Benchmarks for `cuprate-cryptonight`.
|
||||||
|
#![allow(unused_crate_dependencies)]
|
||||||
|
|
||||||
|
mod hash;
|
||||||
|
|
||||||
|
criterion::criterion_main! {
|
||||||
|
hash::benches
|
||||||
|
}
|
2
benches/criterion/cuprate-cryptonight/src/lib.rs
Normal file
2
benches/criterion/cuprate-cryptonight/src/lib.rs
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
//! Benchmark lib for `cuprate-cryptonight`.
|
||||||
|
#![allow(unused_crate_dependencies, reason = "used in benchmarks")]
|
Loading…
Reference in a new issue