aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-02-09 18:52:34 +0000
committerAleksey Kladov <[email protected]>2021-02-09 18:52:34 +0000
commit61f15b72ac52c23148038b3867198597b345e2f6 (patch)
tree0935428e6e79a42da638a5c983ec526c64f10abb /crates/syntax
parent4b1279d0b160d98c1429ca1a52b37aa7a0af5775 (diff)
Add parsing benchmark
Diffstat (limited to 'crates/syntax')
-rw-r--r--crates/syntax/src/tests.rs28
1 files changed, 25 insertions, 3 deletions
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::{
4 path::{Path, PathBuf}, 4 path::{Path, PathBuf},
5}; 5};
6 6
7use ast::NameOwner;
7use expect_test::expect_file; 8use expect_test::expect_file;
8use rayon::prelude::*; 9use rayon::prelude::*;
9use test_utils::project_dir; 10use test_utils::{bench, bench_fixture, project_dir, skip_slow_tests};
10 11
11use crate::{fuzz, tokenize, SourceFile, SyntaxError, TextRange, TextSize, Token}; 12use crate::{ast, fuzz, tokenize, AstNode, SourceFile, SyntaxError, TextRange, TextSize, Token};
12 13
13#[test] 14#[test]
14fn lexer_tests() { 15fn lexer_tests() {
@@ -42,6 +43,28 @@ fn main() {
42} 43}
43 44
44#[test] 45#[test]
46fn benchmark_parser() {
47 if skip_slow_tests() {
48 return;
49 }
50 let data = bench_fixture::glorious_old_parser();
51 let tree = {
52 let _b = bench("parsing");
53 let p = SourceFile::parse(&data);
54 assert!(p.errors.is_empty());
55 assert_eq!(p.tree().syntax.text_range().len(), 352474.into());
56 p.tree()
57 };
58
59 {
60 let _b = bench("tree traversal");
61 let fn_names =
62 tree.syntax().descendants().filter_map(ast::Fn::cast).filter_map(|f| f.name()).count();
63 assert_eq!(fn_names, 268);
64 }
65}
66
67#[test]
45fn parser_tests() { 68fn parser_tests() {
46 dir_tests(&test_data_dir(), &["parser/inline/ok", "parser/ok"], "rast", |text, path| { 69 dir_tests(&test_data_dir(), &["parser/inline/ok", "parser/ok"], "rast", |text, path| {
47 let parse = SourceFile::parse(text); 70 let parse = SourceFile::parse(text);
@@ -128,7 +151,6 @@ fn reparse_fuzz_tests() {
128} 151}
129 152
130/// Test that Rust-analyzer can parse and validate the rust-analyzer 153/// Test that Rust-analyzer can parse and validate the rust-analyzer
131/// FIXME: Use this as a benchmark
132#[test] 154#[test]
133fn self_hosting_parsing() { 155fn self_hosting_parsing() {
134 let dir = project_dir().join("crates"); 156 let dir = project_dir().join("crates");