From e45606e991b47a45bd4919b56b3a599a0d13a7d5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 5 Feb 2013 20:47:02 +0000 Subject: [PATCH] Add benchmarks for wxImage and raw bitmap access to the graphics test. Compare the speed of drawing the bitmaps by synthesizing wxImage and converting it to wxBitmap and directly modifying wxBitmap bits using raw bitmap access. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73471 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- tests/benchmarks/graphics.cpp | 97 +++++++++++++++++++++++++++++++++-- 1 file changed, 94 insertions(+), 3 deletions(-) diff --git a/tests/benchmarks/graphics.cpp b/tests/benchmarks/graphics.cpp index 5ee262844d..95965dc3fd 100644 --- a/tests/benchmarks/graphics.cpp +++ b/tests/benchmarks/graphics.cpp @@ -14,6 +14,8 @@ #include "wx/dcclient.h" #include "wx/dcmemory.h" #include "wx/dcgraph.h" +#include "wx/image.h" +#include "wx/rawbmp.h" #include "wx/stopwatch.h" #include "wx/crt.h" @@ -30,7 +32,9 @@ struct GraphicsBenchmarkOptions numLines = 10000; testBitmaps = + testImages = testLines = + testRawBitmaps = testRectangles = false; usePaint = @@ -48,7 +52,9 @@ struct GraphicsBenchmarkOptions numLines; bool testBitmaps, + testImages, testLines, + testRawBitmaps, testRectangles; bool usePaint, @@ -112,9 +118,11 @@ private: void BenchmarkAll(const wxString& msg, wxDC& dc) { - BenchmarkLines(msg, dc); - BenchmarkRectangles(msg, dc); BenchmarkBitmaps(msg, dc); + BenchmarkImages(msg, dc); + BenchmarkLines(msg, dc); + BenchmarkRawBitmaps(msg, dc); + BenchmarkRectangles(msg, dc); } void BenchmarkLines(const wxString& msg, wxDC& dc) @@ -209,6 +217,82 @@ private: opts.numLines, t, (1000. * t)/opts.numLines); } + void BenchmarkImages(const wxString& msg, wxDC& dc) + { + if ( !opts.testImages ) + return; + + if ( opts.mapMode != 0 ) + dc.SetMapMode((wxMappingMode)opts.mapMode); + + wxPrintf("Benchmarking %s: ", msg); + fflush(stdout); + + wxImage image(wxSize(opts.width, opts.height), false /* don't clear */); + + wxStopWatch sw; + const int numImages = opts.numLines; + for ( int n = 0; n < numImages; n++ ) + { + image.Clear(n % 256); + dc.DrawBitmap(image, 0, 0); + } + + const long t = sw.Time(); + + wxPrintf("%ld images done in %ldms = %gus/image or %d FPS\n", + numImages, t, (1000. * t)/numImages, + (1000*numImages + t - 1)/t); + } + + void BenchmarkRawBitmaps(const wxString& msg, wxDC& dc) + { + if ( !opts.testRawBitmaps ) + return; + + if ( opts.mapMode != 0 ) + dc.SetMapMode((wxMappingMode)opts.mapMode); + + wxPrintf("Benchmarking %s: ", msg); + fflush(stdout); + + wxBitmap bitmap(opts.width, opts.height, 24); + wxNativePixelData data(bitmap); + + wxStopWatch sw; + const int numImages = opts.numLines; + for ( int n = 0; n < numImages; n++ ) + { + const unsigned char c = n % 256; + { + wxNativePixelData::Iterator p(data); + for ( int y = 0; y < opts.height; ++y ) + { + wxNativePixelData::Iterator rowStart = p; + + for ( int x = 0; x < opts.width; ++x ) + { + p.Red() = + p.Green() = + p.Blue() = c; + ++p; + } + + p = rowStart; + p.OffsetY(data, 1); + } + } + + dc.DrawBitmap(bitmap, 0, 0); + } + + const long t = sw.Time(); + + wxPrintf("%ld raw bitmaps done in %ldms = %gus/bitmap or %d FPS\n", + numImages, t, (1000. * t)/numImages, + (1000*numImages + t - 1)/t); + } + wxBitmap m_bitmap; }; @@ -221,7 +305,9 @@ public: static const wxCmdLineEntryDesc desc[] = { { wxCMD_LINE_SWITCH, "", "bitmaps" }, + { wxCMD_LINE_SWITCH, "", "images" }, { wxCMD_LINE_SWITCH, "", "lines" }, + { wxCMD_LINE_SWITCH, "", "rawbmp" }, { wxCMD_LINE_SWITCH, "", "rectangles" }, { wxCMD_LINE_SWITCH, "", "paint" }, { wxCMD_LINE_SWITCH, "", "client" }, @@ -254,13 +340,18 @@ public: return false; opts.testBitmaps = parser.Found("bitmaps"); + opts.testImages = parser.Found("images"); opts.testLines = parser.Found("lines"); + opts.testRawBitmaps = parser.Found("rawbmp"); opts.testRectangles = parser.Found("rectangles"); - if ( !(opts.testBitmaps || opts.testLines || opts.testRectangles) ) + if ( !(opts.testBitmaps || opts.testImages || opts.testLines + || opts.testRawBitmaps || opts.testRectangles) ) { // Do everything by default. opts.testBitmaps = + opts.testImages = opts.testLines = + opts.testRawBitmaps = opts.testRectangles = true; }