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
This commit is contained in:
Vadim Zeitlin 2013-02-05 20:47:02 +00:00
parent 8c14cbc98c
commit e45606e991

View File

@ -14,6 +14,8 @@
#include "wx/dcclient.h" #include "wx/dcclient.h"
#include "wx/dcmemory.h" #include "wx/dcmemory.h"
#include "wx/dcgraph.h" #include "wx/dcgraph.h"
#include "wx/image.h"
#include "wx/rawbmp.h"
#include "wx/stopwatch.h" #include "wx/stopwatch.h"
#include "wx/crt.h" #include "wx/crt.h"
@ -30,7 +32,9 @@ struct GraphicsBenchmarkOptions
numLines = 10000; numLines = 10000;
testBitmaps = testBitmaps =
testImages =
testLines = testLines =
testRawBitmaps =
testRectangles = false; testRectangles = false;
usePaint = usePaint =
@ -48,7 +52,9 @@ struct GraphicsBenchmarkOptions
numLines; numLines;
bool testBitmaps, bool testBitmaps,
testImages,
testLines, testLines,
testRawBitmaps,
testRectangles; testRectangles;
bool usePaint, bool usePaint,
@ -112,9 +118,11 @@ private:
void BenchmarkAll(const wxString& msg, wxDC& dc) void BenchmarkAll(const wxString& msg, wxDC& dc)
{ {
BenchmarkLines(msg, dc);
BenchmarkRectangles(msg, dc);
BenchmarkBitmaps(msg, dc); BenchmarkBitmaps(msg, dc);
BenchmarkImages(msg, dc);
BenchmarkLines(msg, dc);
BenchmarkRawBitmaps(msg, dc);
BenchmarkRectangles(msg, dc);
} }
void BenchmarkLines(const wxString& msg, wxDC& dc) void BenchmarkLines(const wxString& msg, wxDC& dc)
@ -209,6 +217,82 @@ private:
opts.numLines, t, (1000. * t)/opts.numLines); 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; wxBitmap m_bitmap;
}; };
@ -221,7 +305,9 @@ public:
static const wxCmdLineEntryDesc desc[] = static const wxCmdLineEntryDesc desc[] =
{ {
{ wxCMD_LINE_SWITCH, "", "bitmaps" }, { wxCMD_LINE_SWITCH, "", "bitmaps" },
{ wxCMD_LINE_SWITCH, "", "images" },
{ wxCMD_LINE_SWITCH, "", "lines" }, { wxCMD_LINE_SWITCH, "", "lines" },
{ wxCMD_LINE_SWITCH, "", "rawbmp" },
{ wxCMD_LINE_SWITCH, "", "rectangles" }, { wxCMD_LINE_SWITCH, "", "rectangles" },
{ wxCMD_LINE_SWITCH, "", "paint" }, { wxCMD_LINE_SWITCH, "", "paint" },
{ wxCMD_LINE_SWITCH, "", "client" }, { wxCMD_LINE_SWITCH, "", "client" },
@ -254,13 +340,18 @@ public:
return false; return false;
opts.testBitmaps = parser.Found("bitmaps"); opts.testBitmaps = parser.Found("bitmaps");
opts.testImages = parser.Found("images");
opts.testLines = parser.Found("lines"); opts.testLines = parser.Found("lines");
opts.testRawBitmaps = parser.Found("rawbmp");
opts.testRectangles = parser.Found("rectangles"); 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. // Do everything by default.
opts.testBitmaps = opts.testBitmaps =
opts.testImages =
opts.testLines = opts.testLines =
opts.testRawBitmaps =
opts.testRectangles = true; opts.testRectangles = true;
} }