diff --git a/Src/Fare.Benchmarking/Benchmark.cs b/Src/Fare.Benchmarking/Benchmark.cs new file mode 100644 index 0000000..ca01e78 --- /dev/null +++ b/Src/Fare.Benchmarking/Benchmark.cs @@ -0,0 +1,16 @@ +using System; +using BenchmarkDotNet.Attributes; + +namespace Fare.Benchmarking +{ + public class Benchmark + { + private readonly Random random = new Random(); + + [Benchmark] + public Xeger XegerCtorSimple() => new Xeger("."); + + [Benchmark] + public Xeger XegerCtorInjectRandom() => new Xeger(".", this.random); + } +} diff --git a/Src/Fare.Benchmarking/Fare.Benchmarking.csproj b/Src/Fare.Benchmarking/Fare.Benchmarking.csproj new file mode 100644 index 0000000..eba8468 --- /dev/null +++ b/Src/Fare.Benchmarking/Fare.Benchmarking.csproj @@ -0,0 +1,16 @@ + + + + net48 + Exe + + + + + + + + + + + diff --git a/Src/Fare.Benchmarking/Program.cs b/Src/Fare.Benchmarking/Program.cs new file mode 100644 index 0000000..339f16c --- /dev/null +++ b/Src/Fare.Benchmarking/Program.cs @@ -0,0 +1,12 @@ +using BenchmarkDotNet.Running; + +namespace Fare.Benchmarking +{ + public class Program + { + public static void Main(string[] args) + { + BenchmarkRunner.Run(); + } + } +} diff --git a/Src/Fare.IntegrationTests/XegerTests.cs b/Src/Fare.IntegrationTests/XegerTests.cs index 0575163..3337ed4 100644 --- a/Src/Fare.IntegrationTests/XegerTests.cs +++ b/Src/Fare.IntegrationTests/XegerTests.cs @@ -13,7 +13,7 @@ public XegerTests(ITestOutputHelper testOutput) { this._testOutput = testOutput; } - + [Theory, MemberData(nameof(RegexPatternTestCases))] public void GeneratedTextIsCorrect(string pattern) { diff --git a/Src/Fare.sln b/Src/Fare.sln index 0827a9b..8cd521c 100644 --- a/Src/Fare.sln +++ b/Src/Fare.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27130.2020 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30204.135 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fare", "Fare\Fare.csproj", "{24033E0E-0304-4F06-94CD-6F6416ECA509}" EndProject @@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution ..\Build.fsx = ..\Build.fsx EndProjectSection EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Fare.Benchmarking", "Fare.Benchmarking\Fare.Benchmarking.csproj", "{67368248-4A8C-4D5B-B155-4D9307634F40}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,6 +35,12 @@ Global {20F5CC3B-9D71-472A-BD28-3A4C104A00E4}.Release|Any CPU.Build.0 = Release|Any CPU {20F5CC3B-9D71-472A-BD28-3A4C104A00E4}.Verify|Any CPU.ActiveCfg = Verify|Any CPU {20F5CC3B-9D71-472A-BD28-3A4C104A00E4}.Verify|Any CPU.Build.0 = Verify|Any CPU + {67368248-4A8C-4D5B-B155-4D9307634F40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {67368248-4A8C-4D5B-B155-4D9307634F40}.Debug|Any CPU.Build.0 = Debug|Any CPU + {67368248-4A8C-4D5B-B155-4D9307634F40}.Release|Any CPU.ActiveCfg = Release|Any CPU + {67368248-4A8C-4D5B-B155-4D9307634F40}.Release|Any CPU.Build.0 = Release|Any CPU + {67368248-4A8C-4D5B-B155-4D9307634F40}.Verify|Any CPU.ActiveCfg = Debug|Any CPU + {67368248-4A8C-4D5B-B155-4D9307634F40}.Verify|Any CPU.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Src/Fare/Xeger.cs b/Src/Fare/Xeger.cs index 1a425af..eb999b2 100644 --- a/Src/Fare/Xeger.cs +++ b/Src/Fare/Xeger.cs @@ -58,7 +58,10 @@ public Xeger(string regex, Random random) } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class.
+ /// Note that if multiple instances are created within short time using this overload,
+ /// the instances might generate identical random strings.
+ /// To avoid this, use the constructor overload that accepts an argument of type Random. ///
/// The regex. public Xeger(string regex) @@ -138,4 +141,4 @@ private string RemoveStartEndMarkers(string regExp) return regExp; } } -} \ No newline at end of file +}