Created
August 17, 2017 10:15
-
-
Save lomomike/c613199b184e9373baf8638aaf4bd1a9 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
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