-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBenchmark.cs
97 lines (83 loc) · 2.7 KB
/
Benchmark.cs
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using Benchmark;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Running;
using StringExtension;
BenchmarkRunner.Run<StringExtensionBenchmark>(
ManualConfig.Create(DefaultConfig.Instance.WithOptions(ConfigOptions.DisableOptimizationsValidator)));
namespace Benchmark {
/// <summary>
/// Contains benchmarks for the StringExtension methods.
/// </summary>
[MemoryDiagnoser(false)]
public class StringExtensionBenchmark {
private readonly string input = "hello world!";
private readonly char[] charactersToRemove = { 'l', 'o' };
private readonly string substring = "l";
private readonly string phoneNumber = "555-555-5555";
private readonly string email = "[email protected]";
/// <summary>
/// Benchmark for the RemoveCharacters method.
/// </summary>
[Benchmark]
public string RemoveCharacters() {
return input.RemoveCharacters(charactersToRemove);
}
/// <summary>
/// Benchmark for the IsValidEmail method.
/// </summary>
[Benchmark]
public bool IsValidEmail() {
return email.IsValidEmail();
}
/// <summary>
/// Benchmark for the IsValidPhoneNumber method.
/// </summary>
[Benchmark]
public bool IsValidPhoneNumber() {
return phoneNumber.IsValidPhoneNumber();
}
/// <summary>
/// Benchmark for the CountSubstring method.
/// </summary>
[Benchmark]
public int CountSubstring() {
return input.CountSubstring(substring);
}
/// <summary>
/// Benchmark for the ReverseWords method.
/// </summary>
[Benchmark]
public string ReverseWords() {
return input.ReverseWords();
}
/// <summary>
/// Benchmark for the IsPalindrome method.
/// </summary>
[Benchmark]
public bool IsPalindrome() {
return input.IsPalindrome();
}
/// <summary>
/// Benchmark for the CountLetters method.
/// </summary>
[Benchmark]
public int CountLetters() {
return input.CountLetters();
}
/// <summary>
/// Benchmark for the RemoveDuplicateCharacters method.
/// </summary>
[Benchmark]
public string RemoveDuplicateCharacters() {
return input.RemoveDuplicateCharacters();
}
/// <summary>
/// Benchmark for the ConvertToCamelCase method.
/// </summary>
[Benchmark]
public string ConvertToCamelCase() {
return input.ToCamelCase();
}
}
}