2019-01-22 17:01:33 -05:00
|
|
|
#![feature(test)]
|
|
|
|
|
|
|
|
extern crate test;
|
|
|
|
|
|
|
|
mod data;
|
|
|
|
|
|
|
|
#[bench]
|
2019-10-25 17:14:03 -04:00
|
|
|
fn ident_parse_empty(b: &mut test::Bencher) {
|
2020-12-28 22:51:44 -05:00
|
|
|
let parser = typos::tokens::Tokenizer::new();
|
2019-07-23 22:39:09 -04:00
|
|
|
b.iter(|| parser.parse_bytes(data::EMPTY.as_bytes()).last());
|
2019-01-22 17:01:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2019-10-25 17:14:03 -04:00
|
|
|
fn ident_parse_no_tokens(b: &mut test::Bencher) {
|
2020-12-28 22:51:44 -05:00
|
|
|
let parser = typos::tokens::Tokenizer::new();
|
2019-07-23 22:39:09 -04:00
|
|
|
b.iter(|| parser.parse_bytes(data::NO_TOKENS.as_bytes()).last());
|
2019-01-22 17:01:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2019-10-25 17:14:03 -04:00
|
|
|
fn ident_parse_single_token(b: &mut test::Bencher) {
|
2020-12-28 22:51:44 -05:00
|
|
|
let parser = typos::tokens::Tokenizer::new();
|
2019-06-14 08:43:21 -04:00
|
|
|
b.iter(|| {
|
2019-07-23 22:39:09 -04:00
|
|
|
parser.parse_bytes(data::SINGLE_TOKEN.as_bytes()).last();
|
2019-06-14 08:43:21 -04:00
|
|
|
});
|
2019-01-22 17:01:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2019-10-25 17:14:03 -04:00
|
|
|
fn ident_parse_sherlock(b: &mut test::Bencher) {
|
2020-12-28 22:51:44 -05:00
|
|
|
let parser = typos::tokens::Tokenizer::new();
|
2019-07-23 22:39:09 -04:00
|
|
|
b.iter(|| parser.parse_bytes(data::SHERLOCK.as_bytes()).last());
|
2019-01-22 17:01:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2019-10-25 17:14:03 -04:00
|
|
|
fn ident_parse_code(b: &mut test::Bencher) {
|
2020-12-28 22:51:44 -05:00
|
|
|
let parser = typos::tokens::Tokenizer::new();
|
2019-07-23 22:39:09 -04:00
|
|
|
b.iter(|| parser.parse_bytes(data::CODE.as_bytes()).last());
|
2019-01-22 17:01:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2019-10-25 17:14:03 -04:00
|
|
|
fn ident_parse_corpus(b: &mut test::Bencher) {
|
2020-12-28 22:51:44 -05:00
|
|
|
let parser = typos::tokens::Tokenizer::new();
|
2019-07-23 22:39:09 -04:00
|
|
|
b.iter(|| parser.parse_bytes(data::CORPUS.as_bytes()).last());
|
2019-06-16 00:21:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2019-10-25 17:14:03 -04:00
|
|
|
fn ident_split_lowercase_short(b: &mut test::Bencher) {
|
2019-06-16 00:21:40 -04:00
|
|
|
let input = "abcabcabcabc";
|
2019-07-23 22:39:09 -04:00
|
|
|
let symbol = typos::tokens::Identifier::new_unchecked(input, 0);
|
2019-06-16 00:21:40 -04:00
|
|
|
b.iter(|| symbol.split().last());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2019-10-25 17:14:03 -04:00
|
|
|
fn ident_split_lowercase_long(b: &mut test::Bencher) {
|
2019-06-16 00:21:40 -04:00
|
|
|
let input = "abcabcabcabc".repeat(90);
|
2019-07-23 22:39:09 -04:00
|
|
|
let symbol = typos::tokens::Identifier::new_unchecked(&input, 0);
|
2019-06-16 00:21:40 -04:00
|
|
|
b.iter(|| symbol.split().last());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2019-10-25 17:14:03 -04:00
|
|
|
fn ident_split_mixed_short(b: &mut test::Bencher) {
|
2019-06-16 00:21:40 -04:00
|
|
|
let input = "abcABCAbc123";
|
2019-07-23 22:39:09 -04:00
|
|
|
let symbol = typos::tokens::Identifier::new_unchecked(input, 0);
|
2019-06-16 00:21:40 -04:00
|
|
|
b.iter(|| symbol.split().last());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[bench]
|
2019-10-25 17:14:03 -04:00
|
|
|
fn ident_split_mixed_long(b: &mut test::Bencher) {
|
2019-06-16 00:21:40 -04:00
|
|
|
let input = "abcABCAbc123".repeat(90);
|
2019-07-23 22:39:09 -04:00
|
|
|
let symbol = typos::tokens::Identifier::new_unchecked(&input, 0);
|
2019-06-16 00:21:40 -04:00
|
|
|
b.iter(|| symbol.split().last());
|
2019-01-22 17:01:33 -05:00
|
|
|
}
|