Merge pull request #4730 from joshuawarner32/fix-parse-benchmark

Fix parse benchmark and add a benchmark for parsing Num.roc
This commit is contained in:
Joshua Warner 2022-12-10 16:37:00 -08:00 committed by GitHub
commit 521afce1f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,22 +1,43 @@
use std::path::PathBuf;
use bumpalo::Bump;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use roc_parse::{module, module::module_defs, parser::Parser, state::State};
pub fn criterion_benchmark(c: &mut Criterion) {
let mut path = std::env::current_dir()
.unwrap()
.parent()
.unwrap()
.parent()
.unwrap()
.to_owned();
path.push("examples");
path.push("false-interpreter");
path.push("False.roc");
let src = std::fs::read_to_string(&path).unwrap();
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();
@ -34,5 +55,5 @@ pub fn criterion_benchmark(c: &mut Criterion) {
});
}
criterion_group!(benches, criterion_benchmark);
criterion_group!(benches, parse_benchmark);
criterion_main!(benches);