예제 #1
0
        private static void RunSummation()
        {
            var problems = Enumerable.Range(1, BenchmarkTreeSize).Select(n => TreeGenerator.CreateBinaryTree(n, () => Rnd.Next(int.MinValue, int.MaxValue))).ToArray();
            var sumSeq   = new McCollinRunner <Tree <int>, int>(TreeSummer.SumLeaves, problems);
            var sumFJ    = new McCollinRunner <Tree <int>, Task <int> >(TreeSummer.SumLeavesForkJoin, problems);
            var sumL     = new McCollinRunner <Task <Tree <int> >, Task <int> >(TreeSummer.SumLeavesLenient, problems.Select(t => Task.FromResult(t)).ToArray());

            sumSeq.Run(100, m => m.NumberOfLeaves);
            sumFJ.Run(100, m => m.NumberOfLeaves);
            sumL.Run(100, m => m.Result.NumberOfLeaves);

            const string fileName = "summation.csv";

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            var f = new StreamWriter(fileName);

            f.WriteLine("Problem Size,Sequential,Sequential Error,Fork Join,Fork Join Error,Lenient,Lenient Error");

            foreach (var res in sumSeq.Results)
            {
                var fj = sumFJ.Results[res.Key];
                var l  = sumL.Results[res.Key];
                f.WriteLine($"{res.Key},{res.Value.Mean},{res.Value.StandardDeviation},{fj.Mean},{fj.StandardDeviation},{l.Mean},{l.StandardDeviation}");
            }

            f.Flush();
            f.Close();
        }
예제 #2
0
        private static void RunAccumulationRandom()
        {
            var problems = Enumerable.Range(1, BenchmarkTreeSize)
                           .Select(n => (int)Math.Pow(2, n))
                           .Select(s => TreeGenerator.CreateTree(s, () => Rnd.Next(int.MinValue, int.MaxValue)))
                           .ToArray();
            var problemSizes = Enumerable.Range(1, BenchmarkTreeSize).Select(n => (int)Math.Pow(2, n)).ToArray();
            var accumSeq     = new MorellRunner <Tree <int>, List <int> >(TreeAccumulator.AccumulateLeaves, problems, problemSizes);
            var accumFJ      = new MorellRunner <Tree <int>, List <int> >(TreeAccumulator.AccumulateLeavesForkJoin, problems, problemSizes);
            var accumL       = new MorellRunner <Tree <int>, List <int> >(TreeAccumulator.AccumulateLeavesLenient, problems, problemSizes);

            accumSeq.Run(100);
            accumFJ.Run(100);
            accumL.Run(100);

            const string fileName = "accumulation-rand.csv";

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            var f = new StreamWriter(fileName);

            f.WriteLine("Problem Size,Sequential,Sequential Error,Fork Join,Fork Join Error,Lenient,Lenient Error");

            foreach (var res in accumSeq.Results)
            {
                var fj = accumFJ.Results[res.Key];
                var l  = accumL.Results[res.Key];
                f.WriteLine($"{res.Key},{res.Value.Mean},{res.Value.StandardDeviation},{fj.Mean},{fj.StandardDeviation},{l.Mean},{l.StandardDeviation}");
            }

            f.Flush();
            f.Close();
        }