Exemplo n.º 1
0
        public void Verify_AddPerformanceTestRunResults_OneResultFiles_OneResultDirectory()
        {
            // Arrange
            var resultXmlFilePath = EnsureFullPath("results.xml");
            var resultsXmlDir     = EnsureFullPath("Results");
            var args = new[]
            {
                string.Format("--testresultsxmlsource={0}", resultXmlFilePath),
                string.Format("--testresultsxmlsource={0}", resultsXmlDir)
            };

            optionsParser.ParseOptions(PerformanceBenchmark, args);

            // Act
            PerformanceBenchmark.AddPerformanceTestRunResults(testResultXmlParser, performanceTestRunResults, testResults, new List <TestResult>());

            // Assert
            Assert.IsTrue(PerformanceBenchmark.ResultFilesExist);
            AssertCorrectResultsXmlDirectoryPaths(new[] { resultsXmlDir });
            AssertCorrectResultXmlFilePaths(new[] { resultXmlFilePath });
            Assert.NotNull(testResults);
            Assert.IsTrue(testResults.Count > 0);
            Assert.NotNull(performanceTestRunResults);
            Assert.IsTrue(performanceTestRunResults.Count > 0);
        }
Exemplo n.º 2
0
        public void Verify_Verify_AddBaselineAndNonBaselinePerformanceTestRunResults()
        {
            // Arrange
            var resultXmlFilePath   = EnsureFullPath("results.xml");
            var baselineXmlFilePath = EnsureFullPath("baseline.xml");
            var args = new[]
            {
                string.Format("--testresultsxmlsource={0}", resultXmlFilePath),
                string.Format("--baselinexmlsource={0}", baselineXmlFilePath)
            };

            optionsParser.ParseOptions(PerformanceBenchmark, args);

            // Act
            PerformanceBenchmark.AddBaselinePerformanceTestRunResults(testResultXmlParser, baselinePerformanceTestRunResults, baselineTestResults);
            PerformanceBenchmark.AddPerformanceTestRunResults(testResultXmlParser, performanceTestRunResults, testResults, new List <TestResult>());

            // Assert
            Assert.IsTrue(PerformanceBenchmark.ResultFilesExist);
            AssertCorrectResultXmlFilePaths(new[] { resultXmlFilePath });
            Assert.NotNull(testResults);
            Assert.IsTrue(testResults.Count > 0);
            Assert.NotNull(performanceTestRunResults);
            Assert.IsTrue(performanceTestRunResults.Count > 0);

            Assert.IsTrue(PerformanceBenchmark.BaselineResultFilesExist);
            AssertCorrectBaselineXmlFilePaths(new[] { baselineXmlFilePath });
            Assert.NotNull(baselineTestResults);
            Assert.IsTrue(baselineTestResults.Count > 0);
            Assert.NotNull(baselinePerformanceTestRunResults);
            Assert.IsTrue(baselinePerformanceTestRunResults.Count > 0);
        }
Exemplo n.º 3
0
        public void WarpAffineTransform()
        {
            var filePath = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, "Resources\\shannon.jpg");

            var src = MemoryBitmap.Load(filePath, Codecs.OpenCvCodec.Default);
            var dst = new MemoryBitmap(512, 512, src.Info.PixelFormat);

            var xform = System.Numerics.Matrix3x2.CreateScale(1.3f, 1.3f) * System.Numerics.Matrix3x2.CreateRotation(0.25f);

            xform.Translation = new System.Numerics.Vector2(5, 40);

            using (PerformanceBenchmark.Run(t => TestContext.WriteLine($"OpenCV {t}")))
            {
                using var bm = PerformanceBenchmark.Run(result => TestContext.WriteLine(result.TotalMilliseconds));

                OpenCvSharp4Toolkit.WarpAffine(src, dst, xform);
            }
            dst.Save(new AttachmentInfo("result.opencv.jpg"));

            dst.AsSpanBitmap().WritableBytes.Fill(0);
            using (PerformanceBenchmark.Run(t => TestContext.WriteLine($"Soft {t}")))
            {
                using var bm = PerformanceBenchmark.Run(result => TestContext.WriteLine(result.TotalMilliseconds));

                dst.AsSpanBitmap().SetPixels(xform, src);
            }
            dst.Save(new AttachmentInfo("result.soft.jpg"));
        }
        public void Verify_AddMultipleBaselinePerformanceTestRunResultsDirectory()
        {
            // Arrange
            var resultXmlFilePath = EnsureFullPath("results.xml");
            var baselineXmlDir    = EnsureFullPath("Baselines");
            var baselineXmlDir2   = EnsureFullPath("Baselines2");
            var args = new[]
            {
                string.Format("--testresultsxmlsource={0}", resultXmlFilePath),
                string.Format("--baselinexmlsource={0}", baselineXmlDir),
                string.Format("--baselinexmlsource={0}", baselineXmlDir2)
            };

            optionsParser.ParseOptions(PerformanceBenchmark, args);

            // Act
            PerformanceBenchmark.AddBaselinePerformanceTestRunResults(testResultXmlParser, baselinePerformanceTestRunResults,
                                                                      baselineTestResults);

            // Assert
            Assert.IsTrue(PerformanceBenchmark.BaselineResultFilesExist);
            AssertCorrectBaselineXmlDirectoryPaths(new[] { baselineXmlDir, baselineXmlDir2 });
            Assert.NotNull(baselineTestResults);
            Assert.IsTrue(baselineTestResults.Count > 0);
            Assert.NotNull(baselinePerformanceTestRunResults);
            Assert.IsTrue(baselinePerformanceTestRunResults.Count > 0);
        }
Exemplo n.º 5
0
        public void VerifyV1_AddPerformanceTestRunResults_TwoResultFiles()
        {
            // Arrange
            var resultJsonFilePath = EnsureFullPath("results.json");
            var resultFileName2    = EnsureFullPath("results.json");
            var args = new[]
            {
                "--format=json",
                string.Format("--testresultsxmlsource={0}", resultJsonFilePath),
                string.Format("--testresultsxmlsource={0}", resultFileName2)
                , "--version=1"
            };

            optionsParser.ParseOptions(PerformanceBenchmark, args);

            // Act
            PerformanceBenchmark.AddPerformanceTestRunResults(testResultJsonParser, performanceTestRunResults, testResults, new List <TestResult>());

            // Assert
            Assert.IsTrue(PerformanceBenchmark.ResultFilesExist);
            AssertCorrectResultJsonFilePaths(new[] { resultJsonFilePath, resultFileName2 });
            Assert.NotNull(testResults);
            Assert.IsTrue(testResults.Count > 0);
            Assert.NotNull(performanceTestRunResults);
            Assert.IsTrue(performanceTestRunResults.Count > 0);
        }
Exemplo n.º 6
0
        public void VerifyV2_AddBaselinePerformanceTestRunResultsDirectory()
        {
            // Arrange
            var resultJsonFilePath   = EnsureFullPath("results2.json");
            var baselineJsonFilePath = EnsureFullPath("baseline2.json");
            var args = new[]
            {
                "--format=Json",
                string.Format("--testresultsxmlsource={0}", resultJsonFilePath),
                string.Format("--baselinexmlsource={0}", baselineJsonFilePath)
                , "--version=2"
            };

            optionsParser.ParseOptions(PerformanceBenchmark, args);

            // Act
            PerformanceBenchmark.AddBaselinePerformanceTestRunResults(testResultJsonParser, baselinePerformanceTestRunResults, baselineTestResults);

            // Assert
            Assert.IsTrue(PerformanceBenchmark.BaselineResultFilesExist);
            Assert.NotNull(baselineTestResults);
            Assert.IsTrue(baselineTestResults.Count > 0);
            Assert.NotNull(baselinePerformanceTestRunResults);
            Assert.IsTrue(baselinePerformanceTestRunResults.Count > 0);
        }
Exemplo n.º 7
0
 public void Setup()
 {
     optionsParser             = new OptionsParser();
     PerformanceBenchmark      = new PerformanceBenchmark();
     testResultXmlParser       = new TestResultXmlParser();
     performanceTestRunResults = new List <PerformanceTestRunResult>();
     testResults = new List <TestResult>();
     baselinePerformanceTestRunResults = new List <PerformanceTestRunResult>();
     baselineTestResults = new List <TestResult>();
 }
Exemplo n.º 8
0
        public void TestTransform(bool useBilinear)
        {
            var src = LoadShannonImage().OfType <Pixel.BGR24>();

            src.Save(new AttachmentInfo("input.png"));

            var filePath = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, "Resources\\cat.png");
            var cat00    = MemoryBitmap
                           .Load(filePath, Codecs.GDICodec.Default)
                           .OfType <Pixel.BGRA32>();


            filePath = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, "Resources\\QRCode.png");
            var qrcode = MemoryBitmap
                         .Load(filePath, Codecs.GDICodec.Default)
                         .OfType <Pixel.BGRA32>();

            var x = Matrix3x2.CreateScale(0.75f, 0.75f) * Matrix3x2.CreateRotation(0.25f);

            x.Translation = new Vector2(20, 20);
            Matrix3x2.Invert(x, out var xx);

            var dst = new MemoryBitmap <Pixel.BGR24>(512, 512);

            using (PerformanceBenchmark.Run(t => TestContext.WriteLine($"Transform {(int)t.TotalMilliseconds}ms")))
            {
                dst.AsSpanBitmap().SetPixels(xx, src.AsSpanBitmap(), useBilinear);
            }

            for (float r = 0.1f; r < 1; r += 0.2f)
            {
                // 1st API

                var xform = Matrix3x2.CreateRotation(r) * Matrix3x2.CreateTranslation(50, 15);
                xform = Matrix3x2.CreateTranslation(-50, -50) * xform * Matrix3x2.CreateTranslation(50, 50);
                xform = xform * Matrix3x2.CreateScale(3, 3);

                dst.AsSpanBitmap().SetPixels(xform, cat00.AsSpanBitmap(), useBilinear, r);
                DrawBounds(dst, cat00.Bounds, xform, Colors.Red);

                // 2nd API

                xform *= Matrix3x2.CreateTranslation(0, 150);

                dst.AsSpanBitmap().SetPixels(xform, cat00.AsSpanBitmap(), useBilinear, r);
                DrawBounds(dst, cat00.Bounds, xform, Colors.Red);
            }

            dst.AsSpanBitmap().SetPixels(Matrix3x2.CreateScale(3), cat00.AsSpanBitmap(), useBilinear);
            dst.AsSpanBitmap().SetPixels(Matrix3x2.CreateScale(-.6f) * Matrix3x2.CreateTranslation(40, 200), cat00.AsSpanBitmap(), useBilinear);
            dst.AsSpanBitmap().SetPixels(Matrix3x2.CreateScale(.3f) * Matrix3x2.CreateRotation(1) * Matrix3x2.CreateTranslation(150, 300), qrcode.AsSpanBitmap(), useBilinear);

            dst.Save(new AttachmentInfo("transformed.png"));
        }
Exemplo n.º 9
0
        public void TestFlipPerformance(int w, int h, bool multiThread, bool hflip, bool vflip)
        {
            var bmp = new MemoryBitmap <Pixel.RGB24>(w, h).AsSpanBitmap();

            var mirrorEffect = new Processing.BitmapMirror(hflip, vflip, multiThread);

            using (PerformanceBenchmark.Run(t => TestContext.WriteLine($"{w}x{h} HFlip:{hflip} VFlip:{vflip} {Math.Round(t.TotalMilliseconds / 1000)}ms")))
            {
                for (int r = 0; r < 1000; ++r)
                {
                    bmp.ApplyEffect(mirrorEffect);
                }
            }
        }
Exemplo n.º 10
0
        public void LoadJpegPerformanceTest(string filePath)
        {
            TestContext.WriteLine(filePath);
            TestContext.WriteLine("");

            void _writeToTest(string hdr, TimeSpan t)
            {
                TestContext.WriteLine($"{hdr} {t.TotalMilliseconds}ms");
            }

            void _doNothing(string hdr, TimeSpan t)
            {
            }

            Action <string, TimeSpan> _action1 = _writeToTest;
            Action <string, TimeSpan> _action2 = _writeToTest;

            for (int i = 0; i < 3; ++i)
            {
                _action1 = _writeToTest;
                if (i < 2)
                {
                    _action1 = _doNothing;
                }

                _action2 = _doNothing;
                if (i == 0)
                {
                    _action2 = _writeToTest;
                }

                using (var perf = PerformanceBenchmark.Run(result => _action1("OpenCV", result)))
                {
                    var bmp = MemoryBitmap.Load(ResourceInfo.From(filePath), OpenCvCodec.Default);
                    _action2($"OpenCV  OutputFmt: {bmp.PixelFormat}", TimeSpan.Zero);
                }

                using (var perf = PerformanceBenchmark.Run(result => _action1("Skia", result)))
                {
                    var bmp = MemoryBitmap.Load(ResourceInfo.From(filePath), SkiaCodec.Default);
                    _action2($"Skia  OutputFmt: {bmp.PixelFormat}", TimeSpan.Zero);
                }

                using (var perf = PerformanceBenchmark.Run(result => _action1("WPF", result)))
                {
                    var bmp = MemoryBitmap.Load(ResourceInfo.From(filePath), WPFCodec.Default);
                    _action2($"WPF  OutputFmt: {bmp.PixelFormat}", TimeSpan.Zero);
                }

                using (var perf = PerformanceBenchmark.Run(result => _action1("ImageSharp", result)))
                {
                    var bmp = MemoryBitmap.Load(ResourceInfo.From(filePath), ImageSharpCodec.Default);
                    _action2($"ImageSharp  OutputFmt: {bmp.PixelFormat}", TimeSpan.Zero);
                }

                using (var perf = PerformanceBenchmark.Run(result => _action1("GDI", result)))
                {
                    var bmp = MemoryBitmap.Load(ResourceInfo.From(filePath), GDICodec.Default);
                    _action2($"GDI  OutputFmt: {bmp.PixelFormat}", TimeSpan.Zero);
                }

                using (var perf = PerformanceBenchmark.Run(result => _action1("STB", result)))
                {
                    var bmp = MemoryBitmap.Load(ResourceInfo.From(filePath), STBCodec.Default);
                    _action2($"STB  OutputFmt: {bmp.PixelFormat}", TimeSpan.Zero);
                }

                TestContext.WriteLine("");
            }
        }