MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / typical_cpu_metrics

Function typical_cpu_metrics

nodedb-codec/src/alp.rs:455–479  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

453
454 #[test]
455 fn typical_cpu_metrics() {
456 // CPU percentages: 0.0 to 100.0 with 0.1 resolution.
457 let mut values = Vec::with_capacity(10_000);
458 let mut rng: u64 = 42;
459 for _ in 0..10_000 {
460 rng = rng.wrapping_mul(6364136223846793005).wrapping_add(1);
461 let cpu = ((rng >> 33) as f64 / (u32::MAX as f64)) * 100.0;
462 // Round to 0.1 to simulate typical metric resolution.
463 let cpu = (cpu * 10.0).round() / 10.0;
464 values.push(cpu);
465 }
466 let encoded = encode(&values);
467 let decoded = decode(&encoded).unwrap();
468 for (i, (a, b)) in values.iter().zip(decoded.iter()).enumerate() {
469 assert_eq!(a.to_bits(), b.to_bits(), "mismatch at {i}: {a} vs {b}");
470 }
471
472 // ALP should compress much better than raw.
473 let raw_size = values.len() * 8;
474 let ratio = raw_size as f64 / encoded.len() as f64;
475 assert!(
476 ratio > 3.0,
477 "ALP should compress CPU metrics >3x, got {ratio:.1}x"
478 );
479 }
480
481 #[test]
482 fn temperature_readings() {

Callers

nothing calls this directly

Calls 6

roundMethod · 0.80
encodeFunction · 0.70
decodeFunction · 0.70
pushMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected