use std::time::Instant;
use clm_rust_core::hash::raw_hash_bytes;
use clm_rust_core::db::{DbPillarPool, get_card_cached};
fn main() {
println!("=== CLM Kernel Performance Baseline Benchmark ===");
let payload = vec![0x42u8; 1024 * 1024]; let hash_iterations = 100;
let start_hash = Instant::now();
for _ in 0..hash_iterations {
let _h = blake3::hash(&payload);
}
let elapsed_hash = start_hash.elapsed();
let total_mb = (hash_iterations as f64) * 1.0;
let throughput_gb_s = (total_mb / 1024.0) / elapsed_hash.as_secs_f64();
println!(
"BLAKE3 Throughput: {:.2} GB/s ({} MB in {:?})",
throughput_gb_s, total_mb as usize, elapsed_hash
);
let card_sample = r#"
type: mcard
id: "sample_bench_card"
payload:
key1: "value1"
key2: 12345
nested:
inner: true
"#;
let start_canon = Instant::now();
let canon_iterations = 10000;
for _ in 0..canon_iterations {
let _ = raw_hash_bytes(card_sample.as_bytes());
}
let elapsed_canon = start_canon.elapsed();
println!(
"MCard Hashing: {} ops in {:?} ({:.0} ops/sec)",
canon_iterations,
elapsed_canon,
(canon_iterations as f64) / elapsed_canon.as_secs_f64()
);
let d = [
[-1i64, 0i64, 1i64],
[ 1i64, -1i64, 0i64],
[ 0i64, 1i64, -1i64],
];
let mut marking = [1000i64, 1000i64, 1000i64];
let cpn_iterations = 50000;
let start_cpn = Instant::now();
for i in 0..cpn_iterations {
let trans = i % 3;
for row in 0..3 {
marking[row] += d[row][trans];
}
}
let elapsed_cpn = start_cpn.elapsed();
println!(
"CPN Token Transitions: {} firings in {:?} ({:.0} transitions/sec)",
cpn_iterations,
elapsed_cpn,
(cpn_iterations as f64) / elapsed_cpn.as_secs_f64()
);
let temp_dir = tempfile::tempdir().unwrap();
let clm_root = temp_dir.path().to_str().unwrap();
let pool = DbPillarPool::new("content_memory", clm_root).unwrap();
{
let writer_arc = pool.writer();
let mut conn = writer_arc.lock().unwrap();
let tx = conn.transaction().unwrap();
for i in 0..50 {
let hash = format!("card_bench_{:04}", i);
let content = format!("{{\"bench_id\": {}}}", i);
let mut stmt = tx
.prepare_cached("INSERT INTO card (hash, content, g_time) VALUES (?1, ?2, datetime('now'))")
.unwrap();
stmt.execute(rusqlite::params![hash, content]).unwrap();
}
tx.commit().unwrap();
}
let reader = pool.reader().unwrap();
let query_iterations = 20000;
let start_query = Instant::now();
for i in 0..query_iterations {
let target = format!("card_bench_{:04}", i % 50);
let _res = get_card_cached(&reader, &target).unwrap();
}
let elapsed_query = start_query.elapsed();
println!(
"SQLite WAL Reader: {} queries in {:?} ({:.0} queries/sec)",
query_iterations,
elapsed_query,
(query_iterations as f64) / elapsed_query.as_secs_f64()
);
}