diff options
Diffstat (limited to 'crates/ide/src/syntax_highlighting/tests.rs')
-rw-r--r-- | crates/ide/src/syntax_highlighting/tests.rs | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/crates/ide/src/syntax_highlighting/tests.rs b/crates/ide/src/syntax_highlighting/tests.rs index 1b02857ec..933cfa6f3 100644 --- a/crates/ide/src/syntax_highlighting/tests.rs +++ b/crates/ide/src/syntax_highlighting/tests.rs | |||
@@ -1,6 +1,8 @@ | |||
1 | use std::time::Instant; | ||
2 | |||
1 | use expect_test::{expect_file, ExpectFile}; | 3 | use expect_test::{expect_file, ExpectFile}; |
2 | use ide_db::SymbolKind; | 4 | use ide_db::SymbolKind; |
3 | use test_utils::{bench, bench_fixture, skip_slow_tests}; | 5 | use test_utils::{bench, bench_fixture, skip_slow_tests, AssertLinear}; |
4 | 6 | ||
5 | use crate::{fixture, FileRange, HlTag, TextRange}; | 7 | use crate::{fixture, FileRange, HlTag, TextRange}; |
6 | 8 | ||
@@ -258,6 +260,36 @@ fn benchmark_syntax_highlighting_long_struct() { | |||
258 | } | 260 | } |
259 | 261 | ||
260 | #[test] | 262 | #[test] |
263 | fn syntax_highlighting_not_quadratic() { | ||
264 | if skip_slow_tests() { | ||
265 | return; | ||
266 | } | ||
267 | |||
268 | let mut al = AssertLinear::default(); | ||
269 | while al.next_round() { | ||
270 | for i in 6..=10 { | ||
271 | let n = 1 << i; | ||
272 | |||
273 | let fixture = bench_fixture::big_struct_n(n); | ||
274 | let (analysis, file_id) = fixture::file(&fixture); | ||
275 | |||
276 | let time = Instant::now(); | ||
277 | |||
278 | let hash = analysis | ||
279 | .highlight(file_id) | ||
280 | .unwrap() | ||
281 | .iter() | ||
282 | .filter(|it| it.highlight.tag == HlTag::Symbol(SymbolKind::Struct)) | ||
283 | .count(); | ||
284 | assert!(hash > n as usize); | ||
285 | |||
286 | let elapsed = time.elapsed(); | ||
287 | al.sample(n as f64, elapsed.as_millis() as f64); | ||
288 | } | ||
289 | } | ||
290 | } | ||
291 | |||
292 | #[test] | ||
261 | fn benchmark_syntax_highlighting_parser() { | 293 | fn benchmark_syntax_highlighting_parser() { |
262 | if skip_slow_tests() { | 294 | if skip_slow_tests() { |
263 | return; | 295 | return; |