List<string> Count vs Any test

CSharp · Console

/Program.cs

using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
					
public class Program
{
	public static void Main()
	{			
		List<string> query = new List<string>();
		for(int i=0; i<100000;i++)
		{
			query.Add("qwerty");
		}
		

		Stopwatch timeCount = new Stopwatch();
		timeCount.Start();
		if (query.Count > 0)
		{
			
		}
		timeCount.Stop();
		var testCount = timeCount.Elapsed;
		Console.WriteLine("testCount = " + testCount + "\n");
		
		Stopwatch timeAny = new Stopwatch();
		timeAny.Start();
		if (query.Any())
		{
			
		}
		timeAny.Stop();
		var testAny = timeAny.Elapsed;		
		Console.WriteLine("testAny   = " + testAny + "\n");
		
	
	}
}
;