Ejemplo n.º 1
0
        public static void RunParallelMethodTwo()
        {
            var stopwatch = Stopwatch.StartNew();

            var tasks = new List <Task>();

            foreach (var journey in _journeys)
            {
                Task task = new Task(() =>
                                     HaversineService.Calculate(
                                         journey.Item1,
                                         journey.Item2,
                                         journey.Item3,
                                         journey.Item4,
                                         DistanceType.Kilometres));

                task.Start();
                tasks.Add(task);
            }

            Task.WhenAll(tasks.ToArray());

            stopwatch.Stop();

            results.Add("Task.WhenAll", stopwatch.Elapsed);
        }
Ejemplo n.º 2
0
        public static void RunSerialMethodOne()
        {
            var stopwatch = Stopwatch.StartNew();

            foreach (var journey in _journeys)
            {
                var result = HaversineService.Calculate(
                    journey.Item1,
                    journey.Item2,
                    journey.Item3,
                    journey.Item4,
                    DistanceType.Kilometres);
            }

            stopwatch.Stop();

            results.Add("ForEach", stopwatch.Elapsed);
        }
Ejemplo n.º 3
0
        public static void RunParallelMethodFour()
        {
            var stopwatch = Stopwatch.StartNew();

            Task.Run(() => Parallel.ForEach(_journeys, journey =>
            {
                var result = HaversineService.Calculate(
                    journey.Item1,
                    journey.Item2,
                    journey.Item3,
                    journey.Item4,
                    DistanceType.Kilometres);
            }));

            stopwatch.Stop();

            results.Add("Task.Run.Parallel.ForEach", stopwatch.Elapsed);
        }