raw bench

This commit is contained in:
Robin Appelman 2021-08-10 18:20:48 +02:00
commit cba5236496
2 changed files with 21 additions and 4 deletions

View file

@ -1,11 +1,28 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use std::fs::read_to_string;
use tf_log_parser::parse;
use std::time::Duration;
use tf_log_parser::{parse, RawEvent};
pub fn parse_benchmark(c: &mut Criterion) {
let input = read_to_string("test_data/log_2892242.log").unwrap();
c.bench_function("parse 2892242", |b| b.iter(|| parse(black_box(&input))));
}
criterion_group!(benches, parse_benchmark);
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 "))
.flat_map(RawEvent::parse)
.count();
})
});
}
criterion_group!(
name = benches;
config = Criterion::default().measurement_time(Duration::from_secs(10));
targets = parse_benchmark, parse_raw);
criterion_main!(benches);

View file

@ -121,12 +121,12 @@ impl EventHandler for MedicStatsHandler {
GameEvent::MedicDeath(death) => {
let builder = self.0.entry(SteamId3(healer_steam_id)).or_default();
let charge = death.charge.unwrap_or_default();
if charge > 95 && charge < 100 {
if charge >= 95 && charge < 100 {
builder.near_full_charge_death += 1;
} else if charge >= 100 {
builder.drops += 1;
}
if time - builder.last_uber_end <= 20 {
if time - builder.last_uber_end <= 10 {
builder.deaths_after_uber += 1;
}
}