Skip to content

Instantly share code, notes, and snippets.

@aalmada
Last active June 23, 2020 18:18
Show Gist options
  • Select an option

  • Save aalmada/171dac325964abccd8cecb1580174242 to your computer and use it in GitHub Desktop.

Select an option

Save aalmada/171dac325964abccd8cecb1580174242 to your computer and use it in GitHub Desktop.
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using System.Linq;
namespace NetFabric.Hyperlinq.Benchmarks
{
[SimpleJob(RuntimeMoniker.Net472, baseline: true)]
[SimpleJob(RuntimeMoniker.NetCoreApp50)]
[MemoryDiagnoser]
public class RangeContainsBenchmarks
{
[Params(0, 1, 10, 100)]
public int Count { get; set; }
[Benchmark(Baseline = true)]
public bool Condition()
=> Count - 1 >= 0 && Count - 1 < Count;
[Benchmark]
public bool Linq()
=> Enumerable.Range(0, Count).Contains(Count - 1);
[Benchmark]
public bool Hyperlinq()
=> ValueEnumerable.Range(0, Count).Contains(Count - 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment