more event parsers

This commit is contained in:
Robin Appelman 2021-08-24 23:01:07 +02:00
commit 58100e5f7b
8 changed files with 418 additions and 17 deletions

View file

@ -1,20 +1,34 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use std::fs::read_to_string;
use std::time::Duration;
use tf_log_parser::{parse, RawEvent};
use tf_log_parser::{parse, GameEvent, RawEvent};
pub fn parse_benchmark(c: &mut Criterion) {
let input = read_to_string("test_data/log_2892242.log").unwrap();
c.bench_function("parse log 2892242", |b| b.iter(|| parse(black_box(&input))));
}
pub fn parse_event(c: &mut Criterion) {
let input = read_to_string("test_data/log_2892242.log").unwrap();
let raw: Vec<_> = input
.split("L ")
.filter(|line| !line.is_empty())
.flat_map(RawEvent::parse)
.collect();
c.bench_function("parse event 2892242", |b| {
b.iter(|| {
black_box(&raw).iter().flat_map(GameEvent::parse).count();
})
});
}
pub fn parse_raw(c: &mut Criterion) {
let input = read_to_string("test_data/log_2892242.log").unwrap();
c.bench_function("parse raw 2892242", |b| {
b.iter(|| {
black_box(&input)
.lines()
.filter(|line| line.starts_with("L "))
.split("L ")
.filter(|line| !line.is_empty())
.flat_map(RawEvent::parse)
.count();
})
@ -24,5 +38,5 @@ pub fn parse_raw(c: &mut Criterion) {
criterion_group!(
name = benches;
config = Criterion::default().measurement_time(Duration::from_secs(10));
targets = parse_benchmark, parse_raw);
targets = parse_benchmark, parse_raw, parse_event);
criterion_main!(benches);