/// <summary> /// Calculate the method's running time /// </summary> /// <param name="forMethod"></param> /// <returns></returns> public static TimeSpan Runtime(ForMethod forMethod) { var start = DateTime.Now; forMethod(); var stop = DateTime.Now; return(stop - start); }
/// <summary> /// This program shows the differencies between Foreach and Parallel.Foreach /// </summary> /// <param name="args"></param> internal Simulation(int listSize, int forLoopDelay) { Loops loops = new Loops { ListOfSomething = new List <int>(), ForLoopDelay = forLoopDelay }; FillUpList(loops, listSize); ForMethod normalFor = loops.NormalFor; ForMethod parallelFor = loops.ParallelFor; Console.WriteLine("\nNormal foreach:"); var NormalForTime = Stopper.Runtime(normalFor); Console.WriteLine("\nParallel foreach:"); var ParalelForTime = Stopper.Runtime(parallelFor); PrintOutResult(NormalForTime, ParalelForTime, loops.ForLoopDelay); }