From 61f15b72ac52c23148038b3867198597b345e2f6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 9 Feb 2021 21:52:34 +0300 Subject: Add parsing benchmark --- crates/syntax/src/tests.rs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'crates/syntax') diff --git a/crates/syntax/src/tests.rs b/crates/syntax/src/tests.rs index 9d3433c9d..b2c06e24f 100644 --- a/crates/syntax/src/tests.rs +++ b/crates/syntax/src/tests.rs @@ -4,11 +4,12 @@ use std::{ path::{Path, PathBuf}, }; +use ast::NameOwner; use expect_test::expect_file; use rayon::prelude::*; -use test_utils::project_dir; +use test_utils::{bench, bench_fixture, project_dir, skip_slow_tests}; -use crate::{fuzz, tokenize, SourceFile, SyntaxError, TextRange, TextSize, Token}; +use crate::{ast, fuzz, tokenize, AstNode, SourceFile, SyntaxError, TextRange, TextSize, Token}; #[test] fn lexer_tests() { @@ -41,6 +42,28 @@ fn main() { assert!(parse.ok().is_ok()); } +#[test] +fn benchmark_parser() { + if skip_slow_tests() { + return; + } + let data = bench_fixture::glorious_old_parser(); + let tree = { + let _b = bench("parsing"); + let p = SourceFile::parse(&data); + assert!(p.errors.is_empty()); + assert_eq!(p.tree().syntax.text_range().len(), 352474.into()); + p.tree() + }; + + { + let _b = bench("tree traversal"); + let fn_names = + tree.syntax().descendants().filter_map(ast::Fn::cast).filter_map(|f| f.name()).count(); + assert_eq!(fn_names, 268); + } +} + #[test] fn parser_tests() { dir_tests(&test_data_dir(), &["parser/inline/ok", "parser/ok"], "rast", |text, path| { @@ -128,7 +151,6 @@ fn reparse_fuzz_tests() { } /// Test that Rust-analyzer can parse and validate the rust-analyzer -/// FIXME: Use this as a benchmark #[test] fn self_hosting_parsing() { let dir = project_dir().join("crates"); -- cgit v1.2.3