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

Function compression_ratio_structured_logs

nodedb-codec/src/fsst.rs:483–506  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

481
482 #[test]
483 fn compression_ratio_structured_logs() {
484 let mut lines: Vec<Vec<u8>> = Vec::new();
485 for i in 0..5000 {
486 let line = format!(
487 "2024-01-15T10:30:{:02}.000Z INFO server.handler request_id={} method=GET path=/api/v1/metrics status=200 duration_ms={}",
488 i % 60,
489 10000 + i,
490 i * 3 + 1
491 );
492 lines.push(line.into_bytes());
493 }
494 let refs: Vec<&[u8]> = lines.iter().map(|l| l.as_slice()).collect();
495
496 let encoded = encode(&refs);
497 let decoded = decode(&encoded).unwrap();
498 assert_eq!(decoded.len(), lines.len());
499
500 let raw_size: usize = lines.iter().map(|s| s.len()).sum();
501 let ratio = raw_size as f64 / encoded.len() as f64;
502 assert!(
503 ratio > 1.5,
504 "FSST should compress structured logs >1.5x, got {ratio:.1}x"
505 );
506 }
507
508 #[test]
509 fn truncated_input_errors() {

Callers

nothing calls this directly

Calls 8

collectMethod · 0.80
sumMethod · 0.80
encodeFunction · 0.70
decodeFunction · 0.70
pushMethod · 0.45
iterMethod · 0.45
as_sliceMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected