typos/crates/typos-cli/benches/tokenize.rs

101 lines
3.3 KiB
Rust
Raw Normal View History

2024-04-26 22:14:01 -04:00
#![allow(elided_lifetimes_in_paths)]
2019-01-22 17:01:33 -05:00
mod data;
2024-02-07 14:21:10 -05:00
mod parse_str {
2024-04-26 22:14:01 -04:00
use super::data;
2021-02-05 22:38:44 -05:00
2024-02-07 14:21:10 -05:00
#[divan::bench(args = data::DATA)]
fn ascii(bencher: divan::Bencher, sample: &data::Data) {
let unicode = false;
let parser = typos::tokens::TokenizerBuilder::new()
.unicode(unicode)
.build();
bencher
.with_inputs(|| sample.content())
.input_counter(divan::counter::BytesCount::of_str)
2024-04-26 22:14:01 -04:00
.bench_local_values(|sample| parser.parse_str(sample).last());
}
2024-02-07 14:21:10 -05:00
#[divan::bench(args = data::DATA)]
fn unicode(bencher: divan::Bencher, sample: &data::Data) {
let unicode = true;
let parser = typos::tokens::TokenizerBuilder::new()
.unicode(unicode)
.build();
bencher
.with_inputs(|| sample.content())
.input_counter(divan::counter::BytesCount::of_str)
2024-04-26 22:14:01 -04:00
.bench_local_values(|sample| parser.parse_str(sample).last());
}
}
2024-02-07 14:21:10 -05:00
mod parse_bytes {
2024-04-26 22:14:01 -04:00
use super::data;
2024-02-07 14:21:10 -05:00
#[divan::bench(args = data::DATA)]
fn ascii(bencher: divan::Bencher, sample: &data::Data) {
let unicode = false;
let parser = typos::tokens::TokenizerBuilder::new()
.unicode(unicode)
.build();
bencher
.with_inputs(|| sample.content().as_bytes())
.input_counter(divan::counter::BytesCount::of_slice)
2024-04-26 22:14:01 -04:00
.bench_local_values(|sample| parser.parse_bytes(sample).last());
2021-02-05 22:38:44 -05:00
}
2024-02-07 14:21:10 -05:00
#[divan::bench(args = data::DATA)]
fn unicode(bencher: divan::Bencher, sample: &data::Data) {
let unicode = true;
let parser = typos::tokens::TokenizerBuilder::new()
.unicode(unicode)
.build();
bencher
.with_inputs(|| sample.content().as_bytes())
.input_counter(divan::counter::BytesCount::of_slice)
2024-04-26 22:14:01 -04:00
.bench_local_values(|sample| parser.parse_bytes(sample).last());
2024-02-07 14:21:10 -05:00
}
}
#[divan::bench(args = data::DATA)]
fn split(bencher: divan::Bencher, sample: &data::Data) {
let symbol =
typos::tokens::Identifier::new_unchecked(sample.content(), typos::tokens::Case::None, 0);
bencher
.counter(divan::counter::BytesCount::of_str(sample.content()))
2024-04-26 22:14:01 -04:00
.bench_local(|| symbol.split().last());
2021-02-05 22:38:44 -05:00
}
2024-02-07 14:21:10 -05:00
mod parse_split_bytes {
2024-04-26 22:14:01 -04:00
use super::data;
2024-02-07 14:21:10 -05:00
#[divan::bench(args = data::DATA)]
fn ascii(bencher: divan::Bencher, sample: &data::Data) {
let unicode = false;
let parser = typos::tokens::TokenizerBuilder::new()
.unicode(unicode)
.build();
bencher
.with_inputs(|| sample.content().as_bytes())
.input_counter(divan::counter::BytesCount::of_slice)
2024-04-26 22:14:01 -04:00
.bench_local_values(|sample| parser.parse_bytes(sample).flat_map(|i| i.split()).last());
2024-02-07 14:21:10 -05:00
}
#[divan::bench(args = data::DATA)]
fn unicode(bencher: divan::Bencher, sample: &data::Data) {
let unicode = true;
let parser = typos::tokens::TokenizerBuilder::new()
.unicode(unicode)
.build();
bencher
.with_inputs(|| sample.content().as_bytes())
.input_counter(divan::counter::BytesCount::of_slice)
2024-04-26 22:14:01 -04:00
.bench_local_values(|sample| parser.parse_bytes(sample).flat_map(|i| i.split()).last());
}
}
2024-02-07 14:21:10 -05:00
fn main() {
divan::main();
}