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,29 +1,27 @@
#![feature(test)]
extern crate test;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use std::fs;
use test::Bencher;
use tf_demo_parser::{Demo, DemoParser, Stream};
fn bench_file(input_file: &str, b: &mut Bencher) {
fn bench_file(input_file: &str, b: &mut Criterion) {
let file = fs::read(input_file).expect("Unable to read file");
let demo = Demo::new(&file);
let stream: Stream = demo.get_stream();
b.iter(|| {
let (_, state) = DemoParser::new(stream.clone()).parse().unwrap();
test::black_box(state);
})
b.bench_function(&format!("bench file {}", input_file), |b| {
b.iter(|| {
let (_, state) = DemoParser::new(stream.clone()).parse().unwrap();
black_box(state);
})
});
}
#[bench]
fn bench_gully(b: &mut Bencher) {
fn bench_gully(b: &mut Criterion) {
bench_file("test_data/gully.dem", b);
}
#[bench]
fn bench_comp(b: &mut Bencher) {
fn bench_comp(b: &mut Criterion) {
bench_file("test_data/comp.dem", b);
}
criterion_group!(benches, bench_comp, bench_gully);
criterion_main!(benches);