Ejemplo n.º 1
0
        public static void CompareGdToDefault(string segment = "op")
        {
            var settings = new BenchmarkingSettings();

            settings.Images = new ImageProvider();
            settings.Images.AddLocalImages(imageDir, "fountain-small.jpg");
            //.AddBlankImages(new Tuple<int, int, string>[] { new Tuple<int, int, string>(2200, 2200, "jpg") });
            //.AddLocalImages(imageDir, "quality-original.jpg", "fountain-small.jpg");
            settings.SharedInstructions = new Instructions[] { new Instructions(
                                                                   "width=800&scale=both") };
            settings.ExcludeEncoding         = false;
            settings.ExcludeDecoding         = false;
            settings.ExcludeBuilding         = false;
            settings.ExcludeIO               = true;
            settings.ParallelRuns            = 2;
            settings.SegmentNameFilter       = segment;
            settings.ParallelThreads         = parallelThreads;
            settings.SequentialRuns          = 16;
            settings.ThrowawayRuns           = 2;
            settings.ThrowawayThreads        = parallelThreads;
            settings.UseBarrierAroundSegment = true;

            var configs = new Tuple <Config, Instructions, string>[] {
                new Tuple <Config, Instructions, string>(ConfigWithPlugins(), null, "Default"),
                new Tuple <Config, Instructions, string>(ConfigWithPlugins("GdBuilder"), new Instructions("builder=gd"), "GdBuilder")
            };

            Compare(settings, configs.Reverse());
        }
Ejemplo n.º 2
0
 public static void Compare(BenchmarkingSettings settings, IEnumerable <Tuple <string, Instructions> > plugins)
 {
     Compare(settings, plugins.Select(t =>
     {
         return(new Tuple <Config, Instructions, string>(ConfigWithPlugins(t.Item1), t.Item2, t.Item1));
     }));
 }
Ejemplo n.º 3
0
        public static void EvaluateSpeedPlugin()
        {
            var settings = new BenchmarkingSettings();

            settings.Images = new ImageProvider().AddLocalImages(imageDir, "quality-original.jpg", "fountain-small.jpg", "sample.tif", "private\\98613_17.tif");

            var sizes = new List <Instructions>();

            for (int rez = 100; rez < 800; rez += 200)
            {
                sizes.Add(new Instructions()
                {
                    Width = rez
                });
            }
            settings.SharedInstructions = sizes;

            var configs = new List <Tuple <Config, Instructions, string> >();

            configs.Add(new Tuple <Config, Instructions, string>(ConfigWithPlugins(), null, "Default"));

            for (int i = 1; i < 4; i++)
            {
                configs.Add(new Tuple <Config, Instructions, string>(ConfigWithPlugins("SpeedOrQuality"),
                                                                     new Instructions("speed=" + i.ToString()), "SpeedOrQuality plugin"));
            }

            settings.ExcludeDecoding = true;
            settings.ExcludeEncoding = true;
            settings.ExcludeIO       = true;

            Compare(settings, configs);
        }
Ejemplo n.º 4
0
        public static BenchmarkingSettings BenchmarkingDefaults()
        {
            var settings = new BenchmarkingSettings();

            settings.Images          = new ImageProvider();
            settings.ExcludeEncoding = false;
            settings.ExcludeDecoding = false;
            settings.ExcludeBuilding = false;
            settings.ExcludeIO       = true;
            settings.ParallelRuns    = 2;

            settings.ParallelThreads         = parallelThreads;
            settings.SequentialRuns          = 16;
            settings.ThrowawayRuns           = 2;
            settings.ThrowawayThreads        = parallelThreads;
            settings.UseBarrierAroundSegment = true;
            return(settings);
        }
Ejemplo n.º 5
0
        public static void CompareFreeImageToDefault()
        {
            var settings = new BenchmarkingSettings();

            settings.Images             = new ImageProvider().AddLocalImages(imageDir, "quality-original.jpg", "fountain-small.jpg", "sample.tif", "private\\98613_17.tif");
            settings.SharedInstructions = new Instructions[] { new Instructions(
                                                                   "maxwidth=200&maxheight=200"),
                                                               new Instructions() };


            var configs = new Tuple <Config, Instructions, string>[] {
                new Tuple <Config, Instructions, string>(ConfigWithPlugins(), null, "Default"),
                new Tuple <Config, Instructions, string>(ConfigWithPlugins("FreeImageBuilder"), new Instructions("builder=freeimage"), "FreeImageBuilder"),
                new Tuple <Config, Instructions, string>(ConfigWithPlugins("FreeImageDecoder", "FreeImageEncoder"), new Instructions("decoder=freeimage&encoder=freeimage"), "Hybrid (FreeImage encoder/decoder, GDI+ resizer)")
            };

            Compare(settings, configs);

            settings.ExcludeIO = true;

            Compare(settings, configs);
        }
Ejemplo n.º 6
0
        public static void PlotByThreads(BenchmarkingSettings settings,
                                         IEnumerable <Tuple <Config, Instructions, string> > configsAndLabels)
        {
            settings.Images.PrepareImagesAsync().Wait();

            Console.WriteLine();
            String isolation = (settings.SegmentNameFilter != "op" && !settings.UseBarrierAroundSegment) ?
                               "Measuring '" + settings.SegmentNameFilter + "' without memory barrier; multi-threaded results invalid."
                                : (settings.UseBarrierAroundSegment ? "Segment '" + settings.SegmentNameFilter + "' w/ mem barrier."
                                : "Segment '" + settings.SegmentNameFilter + "'.") + (Environment.Is64BitProcess ? " 64-bit" : " 32-bit");

            Console.WriteLine(isolation);

            var combinations = settings.Images.GetImagesAndDescriptions().Combine(settings.SharedInstructions).Combine(configsAndLabels).Select(a => new Tuple <Tuple <string, string>, Instructions, Config, Instructions, string>(a.Item1.Item1, a.Item1.Item2, a.Item2.Item1, a.Item2.Item2, a.Item2.Item3));

            foreach (var c in combinations)
            {
                var combined = c.Item4 == null ? c.Item2 : new Instructions(c.Item4.MergeDefaults(c.Item2));
                var runner   = Benchmark.BenchmarkInMemory(c.Item3, c.Item1.Item1, combined, settings.ExcludeDecoding, settings.ExcludeEncoding);
                runner.Label = c.Item5;

                if (settings.UseBarrierAroundSegment)
                {
                    runner.ProfilerProvider = (s, t) => new JobProfiler(s).JoinThreadsAroundSegment(settings.SegmentNameFilter, t);
                }
                else
                {
                    runner.ProfilerProvider = (s, t) => new JobProfiler(s);
                }

                Console.Write(runner.Label);
                for (var threads = 1; threads <= Environment.ProcessorCount; threads++)
                {
                    if (threads > 1)
                    {
                        runner.SequentialRuns  = 0;
                        runner.ParallelRuns    = settings.ParallelRuns;
                        runner.ParallelThreads = threads;
                    }
                    else
                    {
                        runner.SequentialRuns = settings.SequentialRuns;
                        runner.ParallelRuns   = 0;
                    }

                    runner.ThrowawayThreads = threads;
                    runner.ThrowawayRuns    = settings.ThrowawayRuns;


                    var results = runner.Benchmark();

                    var set = results.FindSet(settings.SegmentNameFilter);


                    var time = threads == 1 ? set.GetStats().SequentialMs.Avg : set.ParallelRealMs();

                    Console.Write(',');
                    Console.Write(time.ToString("f0"));
                }
                Console.WriteLine();
            }
        }
Ejemplo n.º 7
0
        public static void Compare(BenchmarkingSettings settings,
                                   IEnumerable <Tuple <Config, Instructions, string> > configsAndLabels)
        {
            settings.Images.PrepareImagesAsync().Wait();
            foreach (var pair in settings.Images.GetImagesAndDescriptions())
            {
                Console.WriteLine();
                String isolation = (settings.SegmentNameFilter != "op" && !settings.UseBarrierAroundSegment) ?
                                   "Measuring '" + settings.SegmentNameFilter + "' without memory barrier; multi-threaded results invalid."
                                : (settings.UseBarrierAroundSegment ? "Segment '" + settings.SegmentNameFilter + "' w/ mem barrier."
                                : "Segment '" + settings.SegmentNameFilter + "'.");


                Console.WriteLine("Using {0} seq. runs, {1} || on {2} threads({5}). {4} Input: {3}",
                                  settings.SequentialRuns, settings.ParallelRuns, settings.ParallelThreads, pair.Item2, isolation,
                                  Environment.Is64BitProcess ? "64-bit" : "32-bit");

                var widths = CalcColumnWidths(ConsoleWidth, 4, -2, -2, -2, -4);

                Console.WriteLine(Distribute(widths, "Config", "Sequential", "Parallel", "Percent concurrent", "Instructions"));
                foreach (var instructions in settings.SharedInstructions)
                {
                    var comparableResults = configsAndLabels.Select(triple =>
                    {
                        var combined            = triple.Item2 == null ? instructions : new Instructions(triple.Item2.MergeDefaults(instructions));
                        var runner              = Benchmark.BenchmarkInMemory(triple.Item1, pair.Item1, combined, settings.ExcludeDecoding, settings.ExcludeEncoding);
                        runner.ParallelRuns     = settings.ParallelRuns;
                        runner.ParallelThreads  = settings.ParallelThreads;
                        runner.SequentialRuns   = settings.SequentialRuns;
                        runner.Label            = triple.Item3;
                        runner.ThrowawayThreads = settings.ThrowawayThreads;
                        runner.ThrowawayRuns    = settings.ThrowawayRuns;

                        if (settings.UseBarrierAroundSegment)
                        {
                            runner.ProfilerProvider = (s, t) => new JobProfiler(s).JoinThreadsAroundSegment(settings.SegmentNameFilter, t);
                        }
                        else
                        {
                            runner.ProfilerProvider = (s, t) => new JobProfiler(s);
                        }

                        var results = runner.Benchmark();

                        Action <IConcurrencyResults> printStats = r =>
                        {
                            var statStrs = new List <string>(GetStats(triple.Item3, r.GetStats()));
                            statStrs.Add(combined.ToString());
                            Console.WriteLine(Distribute(widths, statStrs.ToArray()));
                        };
                        var set = results.FindSet(settings.SegmentNameFilter);
                        printStats(set);

                        if (settings.ShowProfileTree)
                        {
                            var f = new ConcurrencyResultFormatter();
                            f.DeltaAbnormalRatio         = 1000000;
                            f.ExclusiveTimeSignificantMs = settings.ExclusiveTimeSignificantMs;
                            Console.WriteLine(f.PrintCallTree(set));
                        }
                        return(new Tuple <string, IConcurrencyResults>(triple.Item3, set));
                    }).ToArray();



                    var seqList = comparableResults.OrderBy(r => r.Item2.FastestSequentialMs()).
                                  Select((r, i) => string.Format("{0}. {1} {3:F2}X slower {2}",
                                                                 i + 1, r.Item1, r.Item2.GetStats().SequentialMs.ToString(0.05),
                                                                 r.Item2.FastestSequentialMs() / comparableResults.Min(c => c.Item2.FastestSequentialMs())));


                    Console.WriteLine("Sequential: \n" + string.Join("\n", seqList));

                    var parList = comparableResults.OrderBy(r => r.Item2.ParallelRealMs()).
                                  Select((r, i) => string.Format("{0}. {1} {3:F2}X less throughput {2:F2}ms total. {4:F}% concurrent",
                                                                 i + 1, r.Item1, r.Item2.GetStats().ParallelRealMs,
                                                                 r.Item2.ParallelRealMs() / comparableResults.Min(c => c.Item2.ParallelRealMs()), r.Item2.GetStats().ParallelConcurrencyPercent));

                    Console.WriteLine("Parallel: \n" + string.Join("\n", parList));
                    Console.WriteLine("\n");
                }
            }
        }