Created
January 31, 2022 11:05
-
-
Save kevingosse/f496dead7efb9b105924e5fc43f6f5c2 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
[MemoryDiagnoser] | |
public class EmptyEnumerator | |
{ | |
[Benchmark(Baseline = true)] public bool ArrayEmpty() => Array.Empty<string>().GetEnumerator().MoveNext(); | |
[Benchmark] public bool ArrayEmptyAsEnumerable() => ((IEnumerable<string>)Array.Empty<string>()).GetEnumerator().MoveNext(); | |
[Benchmark] public bool ArrayEmptyForEach() | |
{ | |
foreach (var _ in Array.Empty<string>()) | |
{ | |
return true; | |
} | |
return false; | |
} | |
[Benchmark] public bool EnumerableEmpty() => Enumerable.Empty<string>().GetEnumerator().MoveNext(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment