public static void Benchmark(double insert, double remove, double contains, int size, int numOfThreads) { LFHashTable lfht = new LFHashTable(); List <Task> tasks = new List <Task>(); for (int i = 0; i < numOfThreads; i++) { Queue <int> allNums = new Queue <int>(); Queue <int> allOps = CreateOps(insert, remove, contains, allNums, size); Task task = new Task(() => Start(allOps, allNums, lfht)); tasks.Add(task); } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); foreach (Task task in tasks) { task.Start(); } Task.WaitAll(tasks.ToArray()); stopwatch.Stop(); TimeSpan ts = stopwatch.Elapsed; string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10); Console.WriteLine("Number of threads: " + numOfThreads + " runtime: " + elapsedTime + "s"); }
public static void Start(Queue <int> allOps, Queue <int> nums, LFHashTable lfht) { while (allOps.Count() > 0) { int op = allOps.Dequeue(); switch (op) { case -1: lfht.Remove(nums.Dequeue()); break; case 0: lfht.Contains(nums.Dequeue()); break; case 1: lfht.Insert(nums.Dequeue()); break; } } }