experiments/csharp/E005-RegexCompiledBenchmarks/Program.cs

27 lines
699 B
C#
Raw Normal View History

2024-05-04 21:16:52 +01:00
using System.Text.RegularExpressions;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
BenchmarkRunner.Run<RegexCompiledBenchmarks>();
[SimpleJob, MemoryDiagnoser(false)]
public class RegexCompiledBenchmarks
{
private static readonly Regex RegexInstance = new(@"\d");
private static readonly Regex CompiledRegexInstance = new(@"\d", RegexOptions.Compiled);
[Benchmark]
[Arguments("1234567890")]
public int BasicRegex(string input)
{
return RegexInstance.Matches(input).Count;
}
[Benchmark]
[Arguments("1234567890")]
public int CompiledRegex(string input)
{
return CompiledRegexInstance.Matches(input).Count;
}
}