-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSimdBenchmarks.cs
More file actions
75 lines (61 loc) · 1.86 KB
/
Copy pathSimdBenchmarks.cs
File metadata and controls
75 lines (61 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using BenchmarkDotNet.Attributes;
using NpgsqlRest;
namespace BenchmarkTests;
[MemoryDiagnoser]
public class SimdBenchmarks
{
private string _smallTemplate = null!;
private string _largeTemplate = null!;
private Dictionary<string, string> _replacements = null!;
[GlobalSetup]
public void Setup()
{
// Template inputs
_smallTemplate = "Hello, {name}! Welcome to {place}.";
_largeTemplate = string.Join(" ", Enumerable.Range(1, 100).Select(i => $"{{key{i}}}"));
// Replacements
_replacements = new Dictionary<string, string>
{
{ "name", "John" },
{ "place", "NpgsqlRest" }
};
for (int i = 1; i <= 100; i++)
{
_replacements[$"key{i}"] = $"value{i}";
}
}
#region FormatString Benchmarks
[Benchmark]
public ReadOnlySpan<char> FormatString_Small()
{
return Formatter.FormatString(_smallTemplate.AsSpan(), _replacements);
}
[Benchmark]
public ReadOnlySpan<char> FormatString_Large()
{
return Formatter.FormatString(_largeTemplate.AsSpan(), _replacements);
}
#endregion
#region IsPatternMatch Benchmarks
[Benchmark]
public bool PatternMatch_NoWildcard()
{
return Parser.IsPatternMatch("verylongfilename.txt", "verylongfilename.txt");
}
[Benchmark]
public bool PatternMatch_ExtensionMatch()
{
return Parser.IsPatternMatch("verylongfilename.txt", "*.txt");
}
[Benchmark]
public bool PatternMatch_WildcardMiddle()
{
return Parser.IsPatternMatch("prefix_middle_suffix", "prefix*suffix");
}
[Benchmark]
public bool PatternMatch_LongLiteralPrefix()
{
return Parser.IsPatternMatch("this_is_a_very_long_filename_that_does_not_match.txt", "this_is_a_very_long_filename_that_matches*");
}
#endregion
}