roc/crates/compiler/parse/benches/bench_parse.rs
Joshua Warner e83cd8f191
Re-improve perf of skipping spaces and comments
On my M1 mac this shows as ~25% faster at parsing Num.roc than the old implementation, probably because nobody wrote any NEON code.

Even on my x86_64 linux box (Ryzen 2700x), this shows as 10% faster than the current SSE implementation (running with RUSTFLAGS="-C target-cpu=native").
2022-12-11 08:43:22 -08:00

58 lines
1.7 KiB
Rust

use bumpalo::Bump;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use roc_parse::{module, module::module_defs, parser::Parser, state::State};
use std::path::PathBuf;
pub fn parse_benchmark(c: &mut Criterion) {
c.bench_function("parse false-interpreter", |b| {
let mut path = PathBuf::from(std::env!("ROC_WORKSPACE_DIR"));
path.push("examples");
path.push("cli");
path.push("false-interpreter");
path.push("False.roc");
let src = std::fs::read_to_string(&path).unwrap();
b.iter(|| {
let arena = Bump::new();
let (_actual, state) =
module::parse_header(&arena, State::new(src.as_bytes())).unwrap();
let min_indent = 0;
let res = module_defs()
.parse(&arena, state, min_indent)
.map(|tuple| tuple.1)
.unwrap();
black_box(res.len());
})
});
c.bench_function("parse Num builtin", |b| {
let mut path = PathBuf::from(std::env!("ROC_WORKSPACE_DIR"));
path.push("crates");
path.push("compiler");
path.push("builtins");
path.push("roc");
path.push("Num.roc");
let src = std::fs::read_to_string(&path).unwrap();
b.iter(|| {
let arena = Bump::new();
let (_actual, state) =
module::parse_header(&arena, State::new(src.as_bytes())).unwrap();
let min_indent = 0;
let res = module_defs()
.parse(&arena, state, min_indent)
.map(|tuple| tuple.1)
.unwrap();
black_box(res.len());
})
});
}
criterion_group!(benches, parse_benchmark);
criterion_main!(benches);