Something went wrong. Try again.
A public mirror for the whole atmosphere hubble.microcosm.blue
Something went wrong. Try again.
2.0 kB · 63 lines
Rust
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364//! What the spec's size limits cost us.//!//! A commit CAR may be 2 MB and a record block 1 MB. Real traffic is nowhere//! near that, but a hostile PDS picks its own inputs, so the question is what//! one commit can make the intake task spend before it yields.
use std::time::Instant;
use hubble_commit::cid::Codec;use hubble_commit::{Cid, verify_block};
const CAR_LIMIT: usize = 2 * 1024 * 1024;const RECORD_LIMIT: usize = 1024 * 1024;
fn time_verify(size: usize, iters: usize) -> f64 { let block = vec![0x5au8; size]; let cid = Cid::digest_sha2(Codec::Drisl, &block); // warm up so the first allocation and cache fill are not in the sample for _ in 0..3 { std::hint::black_box(verify_block(&cid, &block).is_ok()); } let start = Instant::now(); for _ in 0..iters { std::hint::black_box(verify_block(&cid, std::hint::black_box(&block)).is_ok()); } start.elapsed().as_secs_f64() * 1e6 / iters as f64}
pub fn run() { println!("block cid verification"); let mut per_mb = 0.0; for (size, iters) in [ (512, 20_000), (4096, 10_000), (65_536, 2_000), (RECORD_LIMIT, 200), ] { let us = time_verify(size, iters); let mb_s = size as f64 / (us * 1e-6) / 1e6; if size == RECORD_LIMIT { per_mb = us; } println!(" {size:>9} bytes {us:>9.2}µs {mb_s:>7.0} MB/s"); }
println!("\nwhat the spec's limits imply"); println!( " one {}-byte record block, hashed: {:>9.0}µs", RECORD_LIMIT, per_mb ); println!( " a full {}-byte CAR, hashed: {:>9.0}µs", CAR_LIMIT, per_mb * (CAR_LIMIT as f64 / RECORD_LIMIT as f64), ); // real commits run about 500 bytes per MST node let nodes = CAR_LIMIT / 506; println!(" a {}-byte CAR of MST nodes ({nodes} of them),", CAR_LIMIT); println!( " inverted at the measured ~2.9µs/node: {:>9.0}µs", nodes as f64 * 2.9 );}