compare_dg_tests.pl: Improve merge() performance
If a test from the reference sum file isn't found in another sum file, then
the function needs to know whether the corresponding exp file is present in
all the sum files being merged.
This was done naively by going through all the tests and doing a string
match, but it turns out that when there are hundreds of thousands of tests,
it takes hours to run.
Fix the problem by adding a new hash to separately record the exp files
present in the sum file. This reduces the merge from hours to seconds.
Change-Id: I4a81349a363022b09395600f08875126b41641f6
diff --git a/compare_dg_tests.pl b/compare_dg_tests.pl
index f70554c..dba648e 100755
--- a/compare_dg_tests.pl
+++ b/compare_dg_tests.pl
@@ -340,7 +340,9 @@
my ($sum_file) = @_;
my $res = empty_result();
my %testcases;
+ my %exp_files;
$res->{testcases} = \%testcases;
+ $res->{exp_files} = \%exp_files;
my $pending_timeout=0;
my $current_tool="";
my $current_exp="";
@@ -393,6 +395,8 @@
{
$current_exp=$1;
$current_exp =~ s|.*/testsuite/||;
+ # For merging, we want to know whether the exp file is present in the result.
+ $exp_files{"$current_tool:$current_exp"} = 1;
}
elsif (m/^\t\t=== (.*) tests ===/)
{
@@ -1095,12 +1099,9 @@
foreach my $result (@results) {
if (not exists $result->{testcases}->{$tc}) {
# Check whether the exp file is present in this result.
- foreach my $key (keys %{$result->{testcases}}) {
- if (index($key, "$current_tool:$current_exp=") == 0) {
- # The exp file is present but this test isn't.
- $test_in_all_results = 0;
- last;
- }
+ if (exists $result->{exp_files}->{"$current_tool:$current_exp"}) {
+ # The exp file is present but this test isn't.
+ $test_in_all_results = 0;
}
} elsif ($result->{testcases}->{$tc}->{PASS}) {
print OUTPUT "PASS: $2\n";