Created
May 20, 2016 10:12
-
-
Save rmaclean/611951ed1a6ef90a781a22190fb0af2e 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; | |
namespace ConsoleApplication2 | |
{ | |
public class ListPerformance | |
{ | |
const int size = 100000; | |
[Benchmark] | |
public void DefaultConstructorUsed() | |
{ | |
var list = new List<int>(); | |
for (int i = 0; i < size; i++) | |
{ | |
list.Add(i); | |
} | |
} | |
[Benchmark] | |
public void ConstructorWithSizeUsed() | |
{ | |
var list = new List<int>(size); | |
for (int i = 0; i < size; i++) | |
{ | |
list.Add(i); | |
} | |
} | |
} | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
BenchmarkDotNet.Running.BenchmarkRunner.Run<ListPerformance>(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment