diff --git a/ci/metrics.py b/ci/metrics.py index f30a9aa..6e04ff8 100644 --- a/ci/metrics.py +++ b/ci/metrics.py @@ -16,7 +16,9 @@ EXPECTED_BENCHES = frozenset({ "bm1362_job_encoding", "bm1366_report_decode", "stratum_header", "stratum_submission", "stratum_authorize_format", "stratum_notify_parse", "stratum_control_parse", "stratum_configure_parse", "difficulty_target", - "stratum_job_issue", "bm1366_session_cycle", + "stratum_job_issue", "bm1366_session_cycle", "bm1362_work_encoding", + "stratum_configure_format", "stratum_subscribe_format", + "stratum_subscription_parse", "stratum_accept_parse", }) BENCH_LINE = re.compile(r"\bBENCH ([A-Za-z0-9_]+) ([0-9]+(?:\.[0-9]+)?) ns/op\Z") diff --git a/tests/bench.rs b/tests/bench.rs index c7dfb43..cc81cff 100644 --- a/tests/bench.rs +++ b/tests/bench.rs @@ -1,6 +1,6 @@ use alkane_os::bm1362::{ - bt8d_for_baud, chain_inactive, encode_job, read_register, read_register_all, set_chip_address, - write_register, write_register_all, Job, S19J_PRO, + bt8d_for_baud, chain_inactive, encode_job, encode_work as encode_bm1362_work, read_register, + read_register_all, set_chip_address, write_register, write_register_all, Job, S19J_PRO, }; use alkane_os::bm1366::{decode_nonce_report, encode_work}; use alkane_os::difficulty::PoolDifficulty; @@ -11,9 +11,10 @@ use alkane_os::scrypt_pow::verify_scrypt_header; use alkane_os::stratum_session::PoolSession; use alkane_os::stratum_submit::{format_submission, Submission}; use alkane_os::stratum_v1::{ - parse_configure_result, parse_control_notification, parse_notify, Subscription, + parse_boolean_response, parse_configure_result, parse_control_notification, parse_notify, + parse_subscription, Subscription, }; -use alkane_os::stratum_wire::authorize_request; +use alkane_os::stratum_wire::{authorize_request, configure_request, subscribe_request}; use alkane_os::stratum_work::Sha256Job; use alkane_os::{power_decision, target_matrix, HardwareBackend}; use std::hint::black_box; @@ -131,6 +132,15 @@ fn bench_bm1362_job_encoding() { }); } +#[test] +#[ignore = "microbenchmark"] +fn bench_bm1362_work_encoding() { + let header = [0_u8; 80]; + measure("bm1362_work_encoding", 20_000, || { + black_box(encode_bm1362_work(black_box(&header), black_box(8))); + }); +} + #[test] #[ignore = "microbenchmark"] fn bench_bm1366_report_decode() { @@ -191,6 +201,40 @@ fn bench_stratum_authorize_format() { }); } +#[test] +#[ignore = "microbenchmark"] +fn bench_stratum_configure_format() { + measure("stratum_configure_format", 20_000, || { + black_box(configure_request(black_box(1))); + }); +} + +#[test] +#[ignore = "microbenchmark"] +fn bench_stratum_subscribe_format() { + measure("stratum_subscribe_format", 20_000, || { + black_box(subscribe_request(black_box(2), "alkane-os/0.1").unwrap()); + }); +} + +#[test] +#[ignore = "microbenchmark"] +fn bench_stratum_subscription_parse() { + let line = br#"{"id":1,"result":[[["mining.notify","session"]],"01020304",4],"error":null}"#; + measure("stratum_subscription_parse", 20_000, || { + black_box(parse_subscription(black_box(line), black_box(1)).unwrap()); + }); +} + +#[test] +#[ignore = "microbenchmark"] +fn bench_stratum_accept_parse() { + let line = br#"{"id":5,"result":true,"error":null}"#; + measure("stratum_accept_parse", 20_000, || { + black_box(parse_boolean_response(black_box(line), black_box(5)).unwrap()); + }); +} + #[test] #[ignore = "microbenchmark"] fn bench_stratum_notify_parse() {