mirror of
https://codeberg.org/demostf/parser.git
synced 2026-06-03 18:24:05 +02:00
bench for a full parse
This commit is contained in:
parent
10253ce76e
commit
ecd19f427f
1 changed files with 53 additions and 0 deletions
53
benches/allmessages.rs
Normal file
53
benches/allmessages.rs
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
#![allow(dead_code)]
|
||||||
|
#![allow(unused_imports)]
|
||||||
|
#![allow(unused_variables)]
|
||||||
|
#![feature(test)]
|
||||||
|
|
||||||
|
extern crate test;
|
||||||
|
|
||||||
|
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;
|
||||||
|
use tf_demo_parser::demo::parser::MessageHandler;
|
||||||
|
use tf_demo_parser::demo::sendprop::SendPropDefinition;
|
||||||
|
use tf_demo_parser::{Demo, DemoParser, MatchState, MessageType, MessageTypeAnalyser, ParserState};
|
||||||
|
|
||||||
|
struct AllMessages;
|
||||||
|
|
||||||
|
impl MessageHandler for AllMessages {
|
||||||
|
type Output = bool;
|
||||||
|
|
||||||
|
fn does_handle(message_type: MessageType) -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_message(&mut self, message: Message, tick: u32) {
|
||||||
|
test::black_box(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_string_entry(&mut self, table: &String, _index: usize, entry: &StringTableEntry) {}
|
||||||
|
|
||||||
|
fn get_output(self, state: ParserState) -> Self::Output {
|
||||||
|
test::black_box(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bench_all(input_file: &str, b: &mut Bencher) {
|
||||||
|
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::parse_with_analyser(stream.clone(), AllMessages).unwrap());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[bench]
|
||||||
|
fn all_test_gully(b: &mut Bencher) {
|
||||||
|
bench_all("data/gully.dem", b);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue