using System.Diagnostics;
using System.Collections.Generic;
public static void Main()
var testList = new List<TestData>();
for (int i = 0; i < 5000; i++)
testList.Add(new TestData{
Stopwatch stopwatch = Stopwatch.StartNew();
Console.WriteLine(testList.Where(x => x.Prop6 % 2 == 0).Count());
Console.WriteLine("First Test");
Console.WriteLine(stopwatch.GetTimeString());
stopwatch = Stopwatch.StartNew();
Console.WriteLine(testList.Count(x => x.Prop6 % 2 == 0));
Console.WriteLine("Second Test");
Console.WriteLine(stopwatch.GetTimeString());
public static class StopwatchExt
public static string GetTimeString(this Stopwatch stopwatch, int numberofDigits = 1)
double time = stopwatch.ElapsedTicks / (double)Stopwatch.Frequency;
return Math.Round(time, numberofDigits) + " s";
return Math.Round(1e3 * time, numberofDigits) + " ms";
return Math.Round(1e6 * time, numberofDigits) + " µs";
return Math.Round(1e9 * time, numberofDigits) + " ns";
return stopwatch.ElapsedTicks + " ticks";
public string Prop1 { get; set; }
public string Prop2 { get; set; }
public string Prop3 { get; set; }
public string Prop4 { get; set; }
public string Prop5 { get; set; }
public int Prop6 { get; set; }