Skip to content

Instantly share code, notes, and snippets.

@lomomike
Created August 17, 2017 10:15
Show Gist options
  • Save lomomike/c613199b184e9373baf8638aaf4bd1a9 to your computer and use it in GitHub Desktop.
Save lomomike/c613199b184e9373baf8638aaf4bd1a9 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace ArraySortBenchmark
{
class Program
{
static void Main(string[] args)
{
var summary = BenchmarkRunner.Run<ArraySortBenchmark>();
}
}
public class ArraySortBenchmark
{
private int[] _array = new int[1000 * 1000];
public ArraySortBenchmark()
{
var random = new Random(42);
for (int i = 0; i < _array.Length; ++i)
{
_array[i] = random.Next();
}
}
[Benchmark]
public void SortWithComparator()
{
Array.Sort(_array, (x, y) => y.CompareTo(x));
}
[Benchmark]
public void SortWithReverse()
{
Array.Sort(_array);
Array.Reverse(_array);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment