mirror of
https://codeberg.org/icewind/tf-log-parser.git
synced 2026-06-03 18:24:09 +02:00
gzip test data
This commit is contained in:
parent
461de19d2e
commit
5defd55037
23 changed files with 62 additions and 34005 deletions
|
|
@ -1,21 +1,28 @@
|
|||
use chrono::NaiveDateTime;
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use std::fs::read_to_string;
|
||||
use flate2::read::GzDecoder;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
use std::time::Duration;
|
||||
use tf_log_parser::{parse, EventHandler, GameEvent, LineSplit, LogHandler, RawEvent, SubjectMap};
|
||||
|
||||
fn gz_read<P: AsRef<Path>>(path: P) -> String {
|
||||
let mut content = String::new();
|
||||
GzDecoder::new(File::open(path).expect("failed to open"))
|
||||
.read_to_string(&mut content)
|
||||
.expect("failed to read");
|
||||
content
|
||||
}
|
||||
|
||||
pub fn parse_benchmark(c: &mut Criterion) {
|
||||
let input = read_to_string("test_data/log_2892242.log").unwrap();
|
||||
let input = gz_read("tests/data/log_2892242.log.gz");
|
||||
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();
|
||||
let input = gz_read("tests/data/log_2892242.log.gz");
|
||||
let raw: Vec<_> = LineSplit::new(&input).flat_map(RawEvent::parse).collect();
|
||||
c.bench_function("parse event 2892242", |b| {
|
||||
b.iter(|| {
|
||||
black_box(&raw).iter().flat_map(GameEvent::parse).count();
|
||||
|
|
@ -24,7 +31,7 @@ pub fn parse_event(c: &mut Criterion) {
|
|||
}
|
||||
|
||||
pub fn parse_raw(c: &mut Criterion) {
|
||||
let input = read_to_string("test_data/log_2892242.log").unwrap();
|
||||
let input = gz_read("tests/data/log_2892242.log.gz");
|
||||
c.bench_function("parse raw 2892242", |b| {
|
||||
b.iter(|| {
|
||||
LineSplit::new(black_box(&input))
|
||||
|
|
@ -36,10 +43,8 @@ pub fn parse_raw(c: &mut Criterion) {
|
|||
}
|
||||
|
||||
pub fn handle_event(c: &mut Criterion) {
|
||||
let input = read_to_string("test_data/log_2892242.log").unwrap();
|
||||
let events: Vec<_> = input
|
||||
.split("L ")
|
||||
.filter(|line| !line.is_empty())
|
||||
let input = gz_read("tests/data/log_2892242.log.gz");
|
||||
let events: Vec<_> = LineSplit::new(&input)
|
||||
.flat_map(RawEvent::parse)
|
||||
.map(|raw| (GameEvent::parse(&raw).unwrap(), raw))
|
||||
.collect();
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::convert::TryFrom;
|
|||
use tf_log_parser::raw_event::RawSubject;
|
||||
use tf_log_parser::{parse, LineSplit, RawEvent, SubjectId};
|
||||
|
||||
static LOG: &str = include_str!("../test_data/log_2892242.log");
|
||||
static LOG: &str = include_str!("../tests/data/log_2892242.log");
|
||||
|
||||
pub fn parse_benchmark() {
|
||||
black_box(parse(black_box(LOG))).ok();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue