46 lines
1.4 KiB
Rust
46 lines
1.4 KiB
Rust
use criterion::{Criterion, criterion_group, criterion_main};
|
|
use logos::Logos;
|
|
use solace::lexer::Token;
|
|
use std::hint::black_box;
|
|
|
|
pub fn criterion_benchmark(c: &mut Criterion) {
|
|
let input = "
|
|
const NUMBER = 1_000_000;
|
|
const HEX_NUMBER = 0x7C1;
|
|
const BIN_NUMBER = 0b10111;
|
|
const OCT_NUMBER = 0o27;
|
|
const INVALID_NUMBER = 0o28;
|
|
const MORE_TOKENS = \"More tokens to fill the 100 Tokens!\";
|
|
|
|
fn easterEgg() -> (output: string) {
|
|
/*
|
|
* Someone found the easter egg!
|
|
* Lets celebrate that with a comment!
|
|
*/
|
|
|
|
output = \"Yeah, you found the easter egg!\";
|
|
}
|
|
|
|
fn main(args: string[]) -> ArgumentError!string {
|
|
if args.length <= 2 {
|
|
return Err(\"Not enough Arguments\", ArgumentError);
|
|
}
|
|
return match args.length {
|
|
3 => \"This is actually just one argument\",
|
|
4 => \"Two arguments. Good!\",
|
|
NUMBER => easterEgg(),
|
|
_ => \"You're overdoing it... maybe?\"
|
|
}
|
|
}
|
|
";
|
|
|
|
c.bench_function("Lexer", |b| {
|
|
b.iter(|| {
|
|
let mut lexer = Token::lexer(black_box(input));
|
|
while let Some(_) = lexer.next() {}
|
|
})
|
|
});
|
|
}
|
|
|
|
criterion_group!(benches, criterion_benchmark);
|
|
criterion_main!(benches);
|