Files
alkane-os/tests/bench.rs
T
noah 751d8c0bda
main-release-gate / verify-and-release (push) Failing after 1m31s
Add reusable BM1366 work and report codec
2026-10-14 19:42:54 -06:00

70 lines
1.8 KiB
Rust

use alkane_os::bm1366::{decode_nonce_report, encode_work};
use alkane_os::pow::verify_sha256_report;
use alkane_os::{power_decision, target_matrix};
use std::hint::black_box;
use std::time::Instant;
fn measure(name: &str, iterations: u64, mut f: impl FnMut()) {
let started = Instant::now();
for _ in 0..iterations {
f();
}
let ns = started.elapsed().as_nanos() as f64 / iterations as f64;
println!("BENCH {name} {ns:.3} ns/op");
}
#[test]
#[ignore = "microbenchmark"]
fn bench_target_matrix() {
measure("target_matrix", 20_000, || {
black_box(
target_matrix()
.filter(|target| black_box(target.chip.algorithm) == alkane_os::Algorithm::Sha256)
.count(),
);
});
}
#[test]
#[ignore = "microbenchmark"]
fn bench_power_policy() {
measure("power_policy", 100_000, || {
black_box(power_decision(black_box(Some(64_000)), 80_000));
});
}
#[test]
#[ignore = "microbenchmark"]
fn bench_share_verification() {
let header = [0_u8; 80];
let target = [0xff_u8; 32];
measure("share_verification", 20_000, || {
black_box(verify_sha256_report(
black_box(&header),
black_box(0xEDAD_FF38),
black_box(0x04B3),
black_box(&target),
));
});
}
#[test]
#[ignore = "microbenchmark"]
fn bench_bm1366_work_encoding() {
let header = [0_u8; 80];
measure("bm1366_work_encoding", 20_000, || {
black_box(encode_work(black_box(&header), black_box(0x18)));
});
}
#[test]
#[ignore = "microbenchmark"]
fn bench_bm1366_report_decode() {
let report = [
0xaa, 0x55, 0x38, 0xff, 0xad, 0xed, 0, 0x18, 0x04, 0xb3, 0x94,
];
measure("bm1366_report_decode", 100_000, || {
let _ = black_box(decode_nonce_report(black_box(&report)));
});
}