Created
March 7, 2024 14:06
-
-
Save habbes/f244a5991f56196f2c3030ecb2a7f8fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Diagnosers; | |
using System; | |
using System.Text; | |
[MemoryDiagnoser] | |
public class Benchmarks | |
{ | |
StringBuilder builder = new StringBuilder(); | |
[GlobalSetup] | |
public void Setup() | |
{ | |
for (int i = 0; i < 10; i++) | |
{ | |
builder.Append("abc"); | |
} | |
} | |
[Benchmark] | |
public bool CheckFirstCharUsingToString() | |
{ | |
return char.IsLetter(builder.ToString(), 0); | |
} | |
[Benchmark] | |
public bool CheckFirstCharUsingIndex() | |
{ | |
return char.IsLetter(builder[0]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment