Skip to content

Commit dd18429

Browse files
authored
move regex to right place to reduce test time (#1388)
1 parent 9b5e52b commit dd18429

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

test/Microsoft.ML.TestFramework/BaseTestBaseline.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ protected BaseTestBaseline(ITestOutputHelper output) : base(output)
5959
private const string OutputRootUnixRegExp = @"\/[^\\\t ]+\/TestOutput" + @"\/[^\\\t ]+";
6060
private static readonly string BinRegUnixExp = @"\/[^\\\t ]+\/bin\/" + Mode;
6161
private static readonly string Bin64RegUnixExp = @"\/[^\\\t ]+\/bin\/x64\/" + Mode;
62+
// The Regex matches both positive and negative decimal point numbers present in a string.
63+
// The numbers could be a part of a word. They can also be in Exponential form eg. 3E-9
64+
private static readonly Regex MatchNumbers = new Regex(@"-?\b[0-9]+\.?[0-9]*(E-[0-9]*)?\b", RegexOptions.IgnoreCase | RegexOptions.Compiled);
6265

6366
/// <summary>
6467
/// When the progress log is appended to the end of output (in test runs), this line precedes the progress log.
@@ -506,16 +509,14 @@ protected bool CheckEqualityFromPathsCore(string relPath, string basePath, strin
506509

507510
private void GetNumbersFromFile(ref string firstString, ref string secondString, int digitsOfPrecision)
508511
{
509-
// The Regex matches both positive and negative decimal point numbers present in a string.
510-
// The numbers could be a part of a word. They can also be in Exponential form eg. 3E-9
511-
Regex _matchNumer = new Regex(@"-?\b[0-9]+\.?[0-9]*(E-[0-9]*)?\b", RegexOptions.IgnoreCase | RegexOptions.Compiled);
512-
MatchCollection firstCollection = _matchNumer.Matches(firstString);
513-
MatchCollection secondCollection = _matchNumer.Matches(secondString);
512+
513+
MatchCollection firstCollection = MatchNumbers.Matches(firstString);
514+
MatchCollection secondCollection = MatchNumbers.Matches(secondString);
514515

515516
if (firstCollection.Count == secondCollection.Count)
516517
MatchNumberWithTolerance(firstCollection, secondCollection, digitsOfPrecision);
517-
firstString = _matchNumer.Replace(firstString, "%Number%");
518-
secondString = _matchNumer.Replace(secondString, "%Number%");
518+
firstString = MatchNumbers.Replace(firstString, "%Number%");
519+
secondString = MatchNumbers.Replace(secondString, "%Number%");
519520
}
520521

521522
private void MatchNumberWithTolerance(MatchCollection firstCollection, MatchCollection secondCollection, int digitsOfPrecision)

0 commit comments

Comments
 (0)