using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text.RegularExpressions;
internal static class MeasureTime
internal static TimeSpan Run(Action func, uint count = 1)
throw new ArgumentOutOfRangeException("count", "Must be greater than zero");
long[] arr_time = new long[count];
Stopwatch sw = new Stopwatch();
for (uint i = 0; i < count; i++)
arr_time[i] = sw.ElapsedTicks;
return new TimeSpan(count == 1 ? arr_time.Sum() : Convert.ToInt64(Math.Round(arr_time.Sum() / (double)count)));
const int max_rnd = 100000;
public static List<int> GetList(int length)
List<int> lst_int = new List<int>(length);
for (int i = 0; i < length; i++)
lst_int.Add(new Random(max_rnd).Next());
public static Hashtable GetHashtable(int length)
Hashtable ht = new Hashtable();
for (int i = 0; i < length; i++)
int cur_rnd = new Random(max_rnd).Next();
public static void Main()
const int count = 1000000;
List<int> lst_int = GetList(count);
int rnd = new Random().Next(max_rnd);
TimeSpan ts1 = MeasureTime.Run(() =>
Console.WriteLine("For random number {0} Contains time is: {1:hh\\:mm\\:ss\\:fff}", rnd, ts1);
Hashtable ht = GetHashtable(count);
TimeSpan ts2 = MeasureTime.Run(() =>
List<int> cur_lst_int = ht.Keys.OfType<int>().ToList();
Console.WriteLine("For random number {0} Hashtable time is: {1:hh\\:mm\\:ss\\:fff}", rnd, ts2);