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

99 lines
3.2 KiB
Rust
Raw Normal View History

2019-01-22 17:01:33 -05:00
mod data;
2024-02-07 14:21:10 -05:00
mod parse_str {
use super::*;
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)
.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)
.bench_local_values(|sample| parser.parse_str(sample).last())
}
}
2024-02-07 14:21:10 -05:00
mod parse_bytes {
use super::*;
#[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)
.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)
.bench_local_values(|sample| parser.parse_bytes(sample).last())
}
}
#[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()))
.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 {
use super::*;
#[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)
.bench_local_values(|sample| parser.parse_bytes(sample).flat_map(|i| i.split()).last())
}
#[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)
.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();
}