benchmark Line formatting

This commit is contained in:
jesopo 2023-03-23 10:42:10 +00:00
parent 3f3892158b
commit 0c38b5bb80
3 changed files with 31 additions and 3 deletions

View File

@ -17,5 +17,8 @@ readme = "README.md"
criterion = "0.4.0"
[[bench]]
name = "basic"
name = "tokenise"
harness = false
[[bench]]
name = "format"
harness = false

25
benches/format.rs Normal file
View File

@ -0,0 +1,25 @@
use std::collections::BTreeMap;
use criterion::{criterion_group, criterion_main, Criterion};
use irctokens::Line;
fn criterion_benchmark(c: &mut Criterion) {
let line = Line {
tags: Some(BTreeMap::from([
("tag1".to_string(), Some("tag1value".to_string())),
("tag2".to_string(), None),
("tag3".to_string(), Some("a;a".to_string())),
])),
source: Some(b"source".to_vec()),
command: "COMMAND".to_string(),
args: Vec::from([
b"arg1".to_vec(),
b"arg2".to_vec(),
b"arg3 with space".to_vec(),
]),
};
c.bench_function("basic", |b| b.iter(|| line.format()));
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);

View File

@ -1,8 +1,8 @@
use criterion::{criterion_group, criterion_main, Criterion};
use irctokens::tokenise;
use irctokens::Line;
fn basic() {
tokenise(b"@tag1=tag1value;tag2=;tag3 :source COMMAND arg1 arg2 :arg3 with space").unwrap();
Line::tokenise(b"@tag1=tag1value;tag2=;tag3 :source COMMAND arg1 arg2 :arg3 with space").unwrap();
}
fn criterion_benchmark(c: &mut Criterion) {