private static void RunBenchmarkSwitcher(LoadResizeSaveParallelMemoryStress lrs, out Stopwatch timer)
        {
            Console.WriteLine(@"Choose a library for image resizing stress test:

1. System.Drawing
2. ImageSharp
3. MagicScaler
4. SkiaSharp
5. SkiaSharp - Decode to target size
6. NetVips
7. ImageMagick
");

            ConsoleKey key = Console.ReadKey().Key;

            if (key < ConsoleKey.D1 || key > ConsoleKey.D6)
            {
                Console.WriteLine("Unrecognized command.");
                Environment.Exit(-1);
            }

            timer = Stopwatch.StartNew();

            switch (key)
            {
            case ConsoleKey.D1:
                lrs.SystemDrawingBenchmarkParallel();
                break;

            case ConsoleKey.D2:
                lrs.ImageSharpBenchmarkParallel();
                break;

            case ConsoleKey.D3:
                lrs.MagicScalerBenchmarkParallel();
                break;

            case ConsoleKey.D4:
                lrs.SkiaBitmapBenchmarkParallel();
                break;

            case ConsoleKey.D5:
                lrs.SkiaBitmapDecodeToTargetSizeBenchmarkParallel();
                break;

            case ConsoleKey.D6:
                lrs.NetVipsBenchmarkParallel();
                break;

            case ConsoleKey.D7:
                lrs.MagickBenchmarkParallel();
                break;
            }

            timer.Stop();
        }
Пример #2
0
        /// <summary>
        /// The main entry point. Useful for executing benchmarks and performance unit tests manually,
        /// when the IDE test runners lack some of the functionality. Eg.: it's not possible to run JetBrains memory profiler for unit tests.
        /// </summary>
        /// <param name="args">
        /// The arguments to pass to the program.
        /// </param>
        public static void Main(string[] args)
        {
            LoadResizeSaveParallelMemoryStress.Run();
            // RunJpegEncoderProfilingTests();
            // RunJpegColorProfilingTests();
            // RunDecodeJpegProfilingTests();
            // RunToVector4ProfilingTest();
            // RunResizeProfilingTest();

            // Console.ReadLine();
        }
Пример #3
0
        /// <summary>
        /// The main entry point. Useful for executing benchmarks and performance unit tests manually,
        /// when the IDE test runners lack some of the functionality. Eg.: it's not possible to run JetBrains memory profiler for unit tests.
        /// </summary>
        /// <param name="args">
        /// The arguments to pass to the program.
        /// </param>
        public static void Main(string[] args)
        {
            try
            {
                LoadResizeSaveParallelMemoryStress.Run(args);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            // RunJpegEncoderProfilingTests();
            // RunJpegColorProfilingTests();
            // RunDecodeJpegProfilingTests();
            // RunToVector4ProfilingTest();
            // RunResizeProfilingTest();

            // Console.ReadLine();
        }
        public static void Run()
        {
            Console.WriteLine(@"Choose a library for image resizing stress test:

1. System.Drawing
2. ImageSharp
3. MagicScaler
4. SkiaSharp
5. NetVips
6. ImageMagick
");

            ConsoleKey key = Console.ReadKey().Key;

            if (key < ConsoleKey.D1 || key > ConsoleKey.D6)
            {
                Console.WriteLine("Unrecognized command.");
                return;
            }

            try
            {
                var lrs = new LoadResizeSaveParallelMemoryStress();

                Console.WriteLine($"\nEnvironment.ProcessorCount={Environment.ProcessorCount}");
                Console.WriteLine($"Running with MaxDegreeOfParallelism={lrs.benchmarks.MaxDegreeOfParallelism} ...");
                var timer = Stopwatch.StartNew();

                switch (key)
                {
                case ConsoleKey.D1:
                    lrs.SystemDrawingBenchmarkParallel();
                    break;

                case ConsoleKey.D2:
                    lrs.ImageSharpBenchmarkParallel();
                    break;

                case ConsoleKey.D3:
                    lrs.MagicScalerBenchmarkParallel();
                    break;

                case ConsoleKey.D4:
                    lrs.SkiaBitmapBenchmarkParallel();
                    break;

                case ConsoleKey.D5:
                    lrs.NetVipsBenchmarkParallel();
                    break;

                case ConsoleKey.D6:
                    lrs.MagickBenchmarkParallel();
                    break;
                }

                timer.Stop();
                var stats = new Stats(timer, lrs.TotalProcessedMegapixels);
                Console.WriteLine("Done. TotalProcessedMegapixels: " + lrs.TotalProcessedMegapixels);
                Console.WriteLine(stats.GetMarkdown());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
        public static void Run(string[] args)
        {
            Console.WriteLine($"Running: {typeof(LoadResizeSaveParallelMemoryStress).Assembly.Location}");
            Console.WriteLine($"64 bit: {Environment.Is64BitProcess}");
            CommandLineOptions options = args.Length > 0 ? CommandLineOptions.Parse(args) : null;

            var lrs = new LoadResizeSaveParallelMemoryStress();

            if (options != null)
            {
                lrs.Benchmarks.MaxDegreeOfParallelism = options.MaxDegreeOfParallelism;
            }

            Console.WriteLine($"\nEnvironment.ProcessorCount={Environment.ProcessorCount}");
            Stopwatch timer;

            if (options == null || !options.ImageSharp)
            {
                RunBenchmarkSwitcher(lrs, out timer);
            }
            else
            {
                Console.WriteLine("Running ImageSharp with options:");
                Console.WriteLine(options.ToString());

                if (!options.KeepDefaultAllocator)
                {
                    Configuration.Default.MemoryAllocator = options.CreateMemoryAllocator();
                }

                lrs.leakFrequency = options.LeakFrequency;
                lrs.gcFrequency   = options.GcFrequency;


                timer = Stopwatch.StartNew();
                try
                {
                    for (int i = 0; i < options.RepeatCount; i++)
                    {
                        lrs.ImageSharpBenchmarkParallel();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                timer.Stop();

                if (options.ReleaseRetainedResourcesAtEnd)
                {
                    Configuration.Default.MemoryAllocator.ReleaseRetainedResources();
                }

                int finalGcCount = -Math.Min(0, options.GcFrequency);

                if (finalGcCount > 0)
                {
                    Console.WriteLine($"TotalOutstandingHandles: {UnmanagedMemoryHandle.TotalOutstandingHandles}");
                    Console.WriteLine($"GC x {finalGcCount}, with 3 seconds wait.");
                    for (int i = 0; i < finalGcCount; i++)
                    {
                        Thread.Sleep(3000);
                        GC.Collect();
                        GC.WaitForPendingFinalizers();
                    }
                }
            }

            var stats = new Stats(timer, lrs.Benchmarks.TotalProcessedMegapixels);

            Console.WriteLine($"Total Megapixels: {stats.TotalMegapixels}, TotalOomRetries: {UnmanagedMemoryHandle.TotalOomRetries}, TotalOutstandingHandles: {UnmanagedMemoryHandle.TotalOutstandingHandles}, Total Gen2 GC count: {GC.CollectionCount(2)}");
            Console.WriteLine(stats.GetMarkdown());
            if (options?.FileOutput != null)
            {
                PrintFileOutput(options.FileOutput, stats);
            }

            if (options != null && options.PauseAtEnd)
            {
                Console.WriteLine("Press ENTER");
                Console.ReadLine();
            }
        }