From c9f324ccdec5e10f12506a8726fe32e91ab4b855 Mon Sep 17 00:00:00 2001 From: desbma-s1n Date: Thu, 30 May 2024 18:28:38 +0200 Subject: [PATCH] perf: add parse_line bench --- src/strace/parser/mod.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/strace/parser/mod.rs b/src/strace/parser/mod.rs index 81aa1f3..0965f14 100644 --- a/src/strace/parser/mod.rs +++ b/src/strace/parser/mod.rs @@ -1730,3 +1730,33 @@ mod tests { ); } } + +#[cfg(all(feature = "nightly", test))] +mod benchs { + extern crate test; + + use std::io::BufReader; + + use super::*; + + use test::Bencher; + + #[bench] + fn bench_parse_line(b: &mut Bencher) { + let log_path = Path::new("strace.log"); + if !log_path.is_file() { + return; + } + let log_lines: Vec<_> = BufReader::new(File::open(log_path).unwrap()) + .lines() + .take(1000) + .collect::>() + .unwrap(); + + b.iter(|| { + for log_line in &log_lines { + let _ = parse_line(&log_line, &[]); + } + }); + } +}