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/ide/src/syntax_highlighting/tests.rs | 37 +++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'crates/ide') diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index 4a1229a31..9d0cd1af5 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs @@ -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] -- cgit v1.2.3