mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +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 ide_db::SymbolKind;
|
||||
use test_utils::{bench, bench_fixture, skip_slow_tests};
|
||||
|
||||
use crate::{fixture, FileRange, TextRange};
|
||||
use crate::{fixture, FileRange, HlTag, TextRange};
|
||||
|
||||
#[test]
|
||||
fn test_highlighting() {
|
||||
@ -226,7 +227,7 @@ fn bar() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn benchmark_syntax_highlighting() {
|
||||
fn benchmark_syntax_highlighting_long_struct() {
|
||||
if skip_slow_tests() {
|
||||
return;
|
||||
}
|
||||
@ -235,10 +236,36 @@ fn benchmark_syntax_highlighting() {
|
||||
let (analysis, file_id) = fixture::file(&fixture);
|
||||
|
||||
let hash = {
|
||||
let _pt = bench("syntax highlighting");
|
||||
analysis.highlight(file_id).unwrap().len()
|
||||
let _pt = bench("syntax highlighting long struct");
|
||||
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]
|
||||
|
@ -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");
|
||||
|
@ -1,7 +1,11 @@
|
||||
//! Generates large snippets of Rust code for usage in the benchmarks.
|
||||
|
||||
use std::fs;
|
||||
|
||||
use stdx::format_to;
|
||||
|
||||
use crate::project_dir;
|
||||
|
||||
pub fn big_struct() -> String {
|
||||
let n = 1_000;
|
||||
|
||||
@ -26,3 +30,8 @@ struct S{} {{
|
||||
|
||||
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