-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathProgram.cs
58 lines (49 loc) · 1.34 KB
/
Program.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
// Made by Benjamin Abt - https://github.com/BenjaminAbt
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
BenchmarkRunner.Run<Benchmark>();
[MemoryDiagnoser]
[SimpleJob(RuntimeMoniker.Net90, baseline: true)]
[HideColumns(Column.Job)]
public class Benchmark
{
[Benchmark]
public bool HasUnicode_NonAggressive()
{
return StringExtensions.HasUnicode_NonAggressive("Hello 🌍! This is a test: 𝒜𝓁𝓅𝒽𝒶, β, γ, δ, ε, Ω, π, ∞, ❤️");
}
[Benchmark]
public bool HasUnicode_Aggressive()
{
return StringExtensions.HasUnicode_Aggressive("Hello 🌍! This is a test: 𝒜𝓁𝓅𝒽𝒶, β, γ, δ, ε, Ω, π, ∞, ❤️");
}
}
public static class StringExtensions
{
public static bool HasUnicode_NonAggressive(string source)
{
foreach (char c in source)
{
if (c > 255)
{
return true;
}
}
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool HasUnicode_Aggressive(string source)
{
foreach (char c in source)
{
if (c > 255)
{
return true;
}
}
return false;
}
}