Skip to content

Commit 02e189d

Browse files
committed
fix: FIx mbe bench tests being iteration order dependent
1 parent 70d0b57 commit 02e189d

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

crates/mbe/src/benchmark.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use intern::Symbol;
44
use rustc_hash::FxHashMap;
55
use span::{Edition, Span};
6+
use stdx::itertools::Itertools;
67
use syntax::{
78
ast::{self, HasName},
89
AstNode,
@@ -27,9 +28,10 @@ fn benchmark_parse_macro_rules() {
2728
let hash: usize = {
2829
let _pt = bench("mbe parse macro rules");
2930
rules
30-
.values()
31-
.map(|it| {
32-
DeclarativeMacro::parse_macro_rules(it, |_| span::Edition::CURRENT).rules.len()
31+
.into_iter()
32+
.sorted_by_key(|(id, _)| id.clone())
33+
.map(|(_, it)| {
34+
DeclarativeMacro::parse_macro_rules(&it, |_| span::Edition::CURRENT).rules.len()
3335
})
3436
.sum()
3537
};
@@ -55,12 +57,13 @@ fn benchmark_expand_macro_rules() {
5557
})
5658
.sum()
5759
};
58-
assert_eq!(hash, 76353);
60+
assert_eq!(hash, 65720);
5961
}
6062

6163
fn macro_rules_fixtures() -> FxHashMap<String, DeclarativeMacro> {
6264
macro_rules_fixtures_tt()
6365
.into_iter()
66+
.sorted_by_key(|(id, _)| id.clone())
6467
.map(|(id, tt)| (id, DeclarativeMacro::parse_macro_rules(&tt, |_| span::Edition::CURRENT)))
6568
.collect()
6669
}
@@ -93,7 +96,7 @@ fn invocation_fixtures(
9396
let mut seed = 123456789;
9497
let mut res = Vec::new();
9598

96-
for (name, it) in rules {
99+
for (name, it) in rules.iter().sorted_by_key(|&(id, _)| id) {
97100
for rule in it.rules.iter() {
98101
// Generate twice
99102
for _ in 0..2 {

0 commit comments

Comments
 (0)