diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-02-09 18:53:27 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-02-09 18:53:27 +0000 |
commit | 4f9a5287bfea124b76571424ce3eb4a91aec337a (patch) | |
tree | cfe365b8382bfae9f8d0bfc9ebc9c35cc6e58307 /crates/syntax | |
parent | 96a9ab725093b5f6501ed086973906ebb77805ff (diff) | |
parent | 61f15b72ac52c23148038b3867198597b345e2f6 (diff) |
Merge #7615
7615: Add parsing benchmark r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/syntax')
-rw-r--r-- | crates/syntax/src/tests.rs | 28 |
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 | ||
7 | use ast::NameOwner; | ||
7 | use expect_test::expect_file; | 8 | use expect_test::expect_file; |
8 | use rayon::prelude::*; | 9 | use rayon::prelude::*; |
9 | use test_utils::project_dir; | 10 | use test_utils::{bench, bench_fixture, project_dir, skip_slow_tests}; |
10 | 11 | ||
11 | use crate::{fuzz, tokenize, SourceFile, SyntaxError, TextRange, TextSize, Token}; | 12 | use crate::{ast, fuzz, tokenize, AstNode, SourceFile, SyntaxError, TextRange, TextSize, Token}; |
12 | 13 | ||
13 | #[test] | 14 | #[test] |
14 | fn lexer_tests() { | 15 | fn lexer_tests() { |
@@ -42,6 +43,28 @@ fn main() { | |||
42 | } | 43 | } |
43 | 44 | ||
44 | #[test] | 45 | #[test] |
46 | fn 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] | ||
45 | fn parser_tests() { | 68 | fn 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] |
133 | fn self_hosting_parsing() { | 155 | fn self_hosting_parsing() { |
134 | let dir = project_dir().join("crates"); | 156 | let dir = project_dir().join("crates"); |