1
0
Fork 0
mirror of https://codeberg.org/demostf/parser.git synced 2026-06-03 10:14:06 +02:00

criterion

This commit is contained in:
Robin Appelman 2022-04-18 17:13:20 +02:00
commit d18a75e34e
5 changed files with 491 additions and 44 deletions

View file

@ -1,15 +1,12 @@
#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(unused_variables)]
#![feature(test)]
extern crate test;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use pretty_assertions::assert_eq;
use std::fs;
use std::collections::{HashMap, HashSet};
use test::Bencher;
use tf_demo_parser::demo::message::Message;
use tf_demo_parser::demo::packet::datatable::{ParseSendTable, SendTableName};
use tf_demo_parser::demo::packet::stringtable::StringTableEntry;
@ -27,28 +24,36 @@ impl MessageHandler for AllMessages {
}
fn handle_message(&mut self, message: &Message, tick: u32) {
test::black_box(message);
black_box(message);
}
fn into_output(self, state: &ParserState) -> Self::Output {
test::black_box(true)
black_box(true)
}
}
fn bench_all(input_file: &str, b: &mut Bencher) {
fn bench_all(input_file: &str, b: &mut Criterion) {
let file = fs::read(input_file).expect("Unable to read file");
let demo = Demo::new(&file);
let stream = demo.get_stream();
b.iter(|| {
let _ = test::black_box(
DemoParser::new_with_analyser(stream.clone(), AllMessages)
.parse()
.unwrap(),
);
b.bench_function("bench_all", |b| {
b.iter(|| {
let _ = black_box(
DemoParser::new_with_analyser(stream.clone(), AllMessages)
.parse()
.unwrap(),
);
})
});
}
#[bench]
fn all_test_gully(b: &mut Bencher) {
fn all_test_gully(b: &mut Criterion) {
bench_all("test_data/gully.dem", b);
}
criterion_group! {
name = benches;
config = Criterion::default().sample_size(10);
targets = all_test_gully
}
criterion_main!(benches);