Skip to content

Instantly share code, notes, and snippets.

@JerryNixon
Created May 25, 2021 16:51
Show Gist options
  • Select an option

  • Save JerryNixon/7c5603ae7549c3b9ab1ca6f358ebb903 to your computer and use it in GitHub Desktop.

Select an option

Save JerryNixon/7c5603ae7549c3b9ab1ca6f358ebb903 to your computer and use it in GitHub Desktop.
public class Program
{
static void Main()
{
BenchmarkRunner.Run<Harness>();
}
}
public class Harness
{
[Benchmark]
public bool ArrayAny() => _array.Any();
[Benchmark]
public bool ArrayCount() => _array.Count() > 0;
[Benchmark]
public bool ListAny() => _list.Any();
[Benchmark]
public bool ListCount() => _list.Count() > 0;
[Benchmark]
public bool EnumerableAny() => _enumerable.Any();
[Benchmark]
public bool EnumerableCount() => _enumerable.Count() > 0;
public static Guid[] _array
= Enumerable.Range(0, 100_000).Select(x => Guid.NewGuid()).ToArray();
public static List<Guid> _list
= Enumerable.Range(0, 100_000).Select(x => Guid.NewGuid()).ToList();
public static IEnumerable<Guid> _enumerable
= Enumerable.Range(0, 100_000).Select(x => Guid.NewGuid());
}
@JerryNixon

Copy link
Copy Markdown
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment