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

Function repetitive_log_lines

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

Source from the content-addressed store, hash-verified

405
406 #[test]
407 fn repetitive_log_lines() {
408 let lines: Vec<&[u8]> = (0..1000)
409 .map(|i| {
410 let s: &[u8] = match i % 5 {
411 0 => b"2024-01-15 INFO server.handler request_id=abc method=GET status=200",
412 1 => b"2024-01-15 INFO server.handler request_id=def method=POST status=201",
413 2 => b"2024-01-15 WARN server.handler request_id=ghi method=GET status=404",
414 3 => b"2024-01-15 ERROR server.handler request_id=jkl method=PUT status=500",
415 _ => b"2024-01-15 DEBUG server.handler request_id=mno method=GET status=200",
416 };
417 s
418 })
419 .collect();
420
421 let encoded = encode(&lines);
422 let decoded = decode(&encoded).unwrap();
423 assert_eq!(decoded.len(), lines.len());
424 for (a, b) in lines.iter().zip(decoded.iter()) {
425 assert_eq!(*a, b.as_slice());
426 }
427
428 // FSST should compress repetitive logs.
429 let raw_size: usize = lines.iter().map(|s| s.len()).sum();
430 let ratio = raw_size as f64 / encoded.len() as f64;
431 assert!(
432 ratio > 1.5,
433 "FSST should compress repetitive logs >1.5x, got {ratio:.1}x"
434 );
435 }
436
437 #[test]
438 fn hostnames() {

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected