From 4edd3f75cecaf44168b4dd554373a54be059b33c Mon Sep 17 00:00:00 2001 From: Boshen Date: Thu, 16 Feb 2023 15:12:31 +0800 Subject: [PATCH] feat(benchmark): check parser before benchmark --- tasks/benchmark/src/main.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tasks/benchmark/src/main.rs b/tasks/benchmark/src/main.rs index a4fbb2dad..26db0203d 100644 --- a/tasks/benchmark/src/main.rs +++ b/tasks/benchmark/src/main.rs @@ -12,8 +12,9 @@ use pico_args::Arguments; #[global_allocator] static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc; +/// # Errors /// # Panics -pub fn main() { +pub fn main() -> Result<(), &'static str> { let mut args = Arguments::from_env(); let baseline: Option = args.opt_value_from_str("--save-baseline").unwrap(); @@ -26,6 +27,18 @@ pub fn main() { let codes = include_str!("./libs.txt").lines().map(|lib| get_code(lib).unwrap()).collect::>(); + // Check files + for (_, code) in &codes { + let allocator = Allocator::default(); + let ret = Parser::new(&allocator, black_box(code), SourceType::default()).parse(); + if !ret.errors.is_empty() { + for error in &ret.errors { + println!("{error:?}"); + } + return Err("Parse Failed."); + } + } + // Bench Parser let mut group = criterion.benchmark_group("parser"); for (id, code) in &codes { @@ -39,4 +52,6 @@ pub fn main() { } group.finish(); + + Ok(()) }