Skip to content

Instantly share code, notes, and snippets.

@kevingosse
Created January 31, 2022 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevingosse/f496dead7efb9b105924e5fc43f6f5c2 to your computer and use it in GitHub Desktop.
Save kevingosse/f496dead7efb9b105924e5fc43f6f5c2 to your computer and use it in GitHub Desktop.
[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