iai benches

This commit is contained in:
Robin Appelman 2021-08-28 15:21:57 +02:00
commit 110cb32c77
3 changed files with 26 additions and 1 deletions

View file

@ -20,7 +20,12 @@ paste = "1"
[dev-dependencies] [dev-dependencies]
criterion = "0.3" criterion = "0.3"
iai = "0.1"
[[bench]] [[bench]]
name = "bench" name = "bench"
harness = false harness = false
[[bench]]
name = "iai"
harness = false

20
benches/iai.rs Normal file
View file

@ -0,0 +1,20 @@
use iai::black_box;
use tf_log_parser::{parse, RawEvent};
static LOG: &str = include_str!("../test_data/log_2892242.log");
pub fn parse_benchmark() {
black_box(parse(black_box(&LOG))).ok();
}
pub fn parse_raw() {
black_box(
black_box(&LOG)
.split("L ")
.filter(|line| !line.is_empty())
.flat_map(RawEvent::parse)
.count(),
);
}
iai::main!(parse_benchmark, parse_raw);

View file

@ -1,4 +1,4 @@
use crate::event::{param_parse, param_parse_with, parse_from_str, position, u_int, ParamIter}; use crate::event::{param_parse, param_parse_with, position, u_int, ParamIter};
use crate::raw_event::{subject_parser, RawSubject}; use crate::raw_event::{subject_parser, RawSubject};
use nom::bytes::complete::{tag, take_while}; use nom::bytes::complete::{tag, take_while};
use nom::combinator::opt; use nom::combinator::opt;