mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 23:12:02 +00:00
Add parsing benchmark
This commit is contained in:
parent
4b1279d0b1
commit
61f15b72ac
8562
bench_data/glorious_old_parser
Normal file
8562
bench_data/glorious_old_parser
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,7 +1,8 @@
|
|||||||
use expect_test::{expect_file, ExpectFile};
|
use expect_test::{expect_file, ExpectFile};
|
||||||
|
use ide_db::SymbolKind;
|
||||||
use test_utils::{bench, bench_fixture, skip_slow_tests};
|
use test_utils::{bench, bench_fixture, skip_slow_tests};
|
||||||
|
|
||||||
use crate::{fixture, FileRange, TextRange};
|
use crate::{fixture, FileRange, HlTag, TextRange};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_highlighting() {
|
fn test_highlighting() {
|
||||||
@ -226,7 +227,7 @@ fn bar() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn benchmark_syntax_highlighting() {
|
fn benchmark_syntax_highlighting_long_struct() {
|
||||||
if skip_slow_tests() {
|
if skip_slow_tests() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -235,10 +236,36 @@ fn benchmark_syntax_highlighting() {
|
|||||||
let (analysis, file_id) = fixture::file(&fixture);
|
let (analysis, file_id) = fixture::file(&fixture);
|
||||||
|
|
||||||
let hash = {
|
let hash = {
|
||||||
let _pt = bench("syntax highlighting");
|
let _pt = bench("syntax highlighting long struct");
|
||||||
analysis.highlight(file_id).unwrap().len()
|
analysis
|
||||||
|
.highlight(file_id)
|
||||||
|
.unwrap()
|
||||||
|
.iter()
|
||||||
|
.filter(|it| it.highlight.tag == HlTag::Symbol(SymbolKind::Struct))
|
||||||
|
.count()
|
||||||
};
|
};
|
||||||
assert_eq!(hash, 32009);
|
assert_eq!(hash, 2001);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn benchmark_syntax_highlighting_parser() {
|
||||||
|
if skip_slow_tests() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let fixture = bench_fixture::glorious_old_parser();
|
||||||
|
let (analysis, file_id) = fixture::file(&fixture);
|
||||||
|
|
||||||
|
let hash = {
|
||||||
|
let _pt = bench("syntax highlighting parser");
|
||||||
|
analysis
|
||||||
|
.highlight(file_id)
|
||||||
|
.unwrap()
|
||||||
|
.iter()
|
||||||
|
.filter(|it| it.highlight.tag == HlTag::Symbol(SymbolKind::Function))
|
||||||
|
.count()
|
||||||
|
};
|
||||||
|
assert_eq!(hash, 1629);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -4,11 +4,12 @@ use std::{
|
|||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use ast::NameOwner;
|
||||||
use expect_test::expect_file;
|
use expect_test::expect_file;
|
||||||
use rayon::prelude::*;
|
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]
|
#[test]
|
||||||
fn lexer_tests() {
|
fn lexer_tests() {
|
||||||
@ -41,6 +42,28 @@ fn main() {
|
|||||||
assert!(parse.ok().is_ok());
|
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]
|
#[test]
|
||||||
fn parser_tests() {
|
fn parser_tests() {
|
||||||
dir_tests(&test_data_dir(), &["parser/inline/ok", "parser/ok"], "rast", |text, path| {
|
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
|
/// Test that Rust-analyzer can parse and validate the rust-analyzer
|
||||||
/// FIXME: Use this as a benchmark
|
|
||||||
#[test]
|
#[test]
|
||||||
fn self_hosting_parsing() {
|
fn self_hosting_parsing() {
|
||||||
let dir = project_dir().join("crates");
|
let dir = project_dir().join("crates");
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
//! Generates large snippets of Rust code for usage in the benchmarks.
|
//! Generates large snippets of Rust code for usage in the benchmarks.
|
||||||
|
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
use stdx::format_to;
|
use stdx::format_to;
|
||||||
|
|
||||||
|
use crate::project_dir;
|
||||||
|
|
||||||
pub fn big_struct() -> String {
|
pub fn big_struct() -> String {
|
||||||
let n = 1_000;
|
let n = 1_000;
|
||||||
|
|
||||||
@ -26,3 +30,8 @@ struct S{} {{
|
|||||||
|
|
||||||
buf
|
buf
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn glorious_old_parser() -> String {
|
||||||
|
let path = project_dir().join("bench_data/glorious_old_parser");
|
||||||
|
fs::read_to_string(&path).unwrap()
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user