private static void DoItAndTimetIt(IIncrement toIncrement) { int iterations = 1000000000; Task[] tasks = new Task[2]; Barrier barrier = new Barrier(tasks.Length + 1); for (int nTask = 0; nTask < tasks.Length; nTask++) { int localTask = nTask; tasks[nTask] = Task.Factory.StartNew(() => { barrier.SignalAndWait(); for (int i = 0; i < 1000000000; i++) { toIncrement.Increment(localTask); } }); } barrier.SignalAndWait(); Stopwatch timer = Stopwatch.StartNew(); Task.WaitAll(tasks); timer.Stop(); Console.WriteLine("{0} took {1}", toIncrement.GetType().Name, timer.Elapsed); }
public void Increment(int by = 1) { _incrementer.Increment(by); }