code wiki / (root) / nx_hash_bench_run.nx

nx_hash_bench_run.nx source

↩ module page · 39 lines · 2374 B

1// nx_hash_bench_run.nx -- measures + prints our SHA-1/SHA-256 hashing throughput. 2// Run output is redirected to knowledge/status/hash_throughput.log (the first concrete 3// hashing-MB/s figure in the field -- no incumbent publishes one). Timing = wall-clock, 4// non-deterministic, single-run: a MEASUREMENT, not a gate. Correctness is gated by 5// nx_hash_bench_test. exit 0 always (unless the KAT fails, which would mean broken crypto). 6 7import "nx_hash_bench.nx" 8import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc) 9const K_MAGIC_1000000: i64 = 1000000 10 11func _r_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 12// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer 13// per call and never freed it. At page granularity that is 4096B leaked PER CALL -- the 14// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff. A BENCH is the worst home for 15// it: its purpose is millions of iterations. nxi_* is MSB-first and allocates NOTHING. 16func _r_putn(v: i64) -> i64 { nxi_out(v); return 0 } 17 18func main() -> i64 { 19 // correctness guard first -- never publish a throughput number from a broken hash 20 if nx_hb_sha1_ok() != 1 { _r_puts("SHA1 KAT FAIL\n" as *u8); sys_exit(1); return 1 } 21 if nx_hb_sha256_ok() != 1 { _r_puts("SHA256 KAT FAIL\n" as *u8); sys_exit(1); return 1 } 22 23 let n: i64 = K_MAGIC_1000000 // 1 MB buffer (== 1 MB by the MB=1e6 convention) 24 let iters: i64 = 4 // 4 MB hashed per algorithm -- keeps the run inside the time budget 25 let buf: *u8 = sys_mmap(n) 26 nx_hb_fill(buf, n) 27 28 let s1: i64 = nx_hb_sha1_mbps(buf, n, iters) 29 let s2: i64 = nx_hb_sha256_mbps(buf, n, iters) 30 31 _r_puts("=== NISHI sovereign hashing throughput (MEASURED, single-run wall-clock) ===\n" as *u8) 32 _r_puts("workload: " as *u8); _r_putn(n); _r_puts(" B x " as *u8); _r_putn(iters) 33 _r_puts(" iters = " as *u8); _r_putn((n * iters) / K_MAGIC_1000000); _r_puts(" MB per algorithm\n" as *u8) 34 _r_puts("SHA-1 (BEP-3 piece hash) : " as *u8); _r_putn(s1); _r_puts(" MB/s\n" as *u8) 35 _r_puts("SHA-256 (BEP-52 v2 leaf) : " as *u8); _r_putn(s2); _r_puts(" MB/s\n" as *u8) 36 _r_puts("incumbents: UNPUBLISHED (no client ships a concrete hashing MB/s figure) -- this is the first.\n" as *u8) 37 sys_exit(0) 38 return 0 39}