Benchmark GetTextExtent() and GetPartialTextExtents()

Add very simple benchmark of these 2 functions to allow (roughly)
comparing the advantage of using one compared to the other.
This commit is contained in:
Vadim Zeitlin 2020-03-07 19:22:55 +01:00
parent c124a43fc1
commit 1e7c2c8254

View File

@ -64,7 +64,9 @@ struct GraphicsBenchmarkOptions
testRawBitmaps =
testRectangles =
testCircles =
testEllipses = false;
testEllipses =
testTextExtent =
testPartialTextExtents = false;
usePaint =
useClient =
@ -91,7 +93,9 @@ struct GraphicsBenchmarkOptions
testRawBitmaps,
testRectangles,
testCircles,
testEllipses;
testEllipses,
testTextExtent,
testPartialTextExtents;
bool usePaint,
useClient,
@ -396,6 +400,8 @@ private:
BenchmarkRoundedRectangles(msg, dc);
BenchmarkCircles(msg, dc);
BenchmarkEllipses(msg, dc);
BenchmarkTextExtent(msg, dc);
BenchmarkPartialTextExtents(msg, dc);
}
void SetupDC(wxDC& dc)
@ -612,6 +618,60 @@ private:
opts.numIters, t, (1000. * t)/opts.numIters);
}
void BenchmarkTextExtent(const wxString& msg, wxDC& dc)
{
if ( !opts.testTextExtent )
return;
SetupDC(dc);
wxPrintf("Benchmarking %s: ", msg);
fflush(stdout);
const wxString str("The quick brown fox jumps over the lazy dog");
wxSize size;
wxStopWatch sw;
for ( long n = 0; n < opts.numIters; n++ )
{
size += dc.GetTextExtent(str);
}
const long t = sw.Time();
wxPrintf("%ld text extent measures done in %ldms = %gus/call\n",
opts.numIters, t, (1000. * t)/opts.numIters);
}
void BenchmarkPartialTextExtents(const wxString& msg, wxDC& dc)
{
if ( !opts.testPartialTextExtents )
return;
SetupDC(dc);
wxPrintf("Benchmarking %s: ", msg);
fflush(stdout);
const wxString str("The quick brown fox jumps over the lazy dog");
wxArrayInt widths;
wxStopWatch sw;
for ( long n = 0; n < opts.numIters; n++ )
{
if ( !dc.GetPartialTextExtents(str, widths) )
{
wxPrintf("ERROR: GetPartialTextExtents() failed\n");
return;
}
}
const long t = sw.Time();
wxPrintf("%ld partial text extents measures done in %ldms = %gus/call\n",
opts.numIters, t, (1000. * t)/opts.numIters);
}
void BenchmarkBitmaps(const wxString& msg, wxDC& dc)
{
if ( !opts.testBitmaps )
@ -786,6 +846,8 @@ public:
{ wxCMD_LINE_SWITCH, "", "rectangles" },
{ wxCMD_LINE_SWITCH, "", "circles" },
{ wxCMD_LINE_SWITCH, "", "ellipses" },
{ wxCMD_LINE_SWITCH, "", "textextent" },
{ wxCMD_LINE_SWITCH, "", "partialtextextents" },
{ wxCMD_LINE_SWITCH, "", "paint" },
{ wxCMD_LINE_SWITCH, "", "client" },
{ wxCMD_LINE_SWITCH, "", "memory" },
@ -859,9 +921,12 @@ public:
opts.testRectangles = parser.Found("rectangles");
opts.testCircles = parser.Found("circles");
opts.testEllipses = parser.Found("ellipses");
opts.testTextExtent = parser.Found("textextent");
opts.testPartialTextExtents = parser.Found("partialtextextents");
if ( !(opts.testBitmaps || opts.testImages || opts.testLines
|| opts.testRawBitmaps || opts.testRectangles
|| opts.testCircles || opts.testEllipses) )
|| opts.testCircles || opts.testEllipses
|| opts.testTextExtent || opts.testPartialTextExtents) )
{
// Do everything by default.
opts.testBitmaps =
@ -870,7 +935,9 @@ public:
opts.testRawBitmaps =
opts.testRectangles =
opts.testCircles =
opts.testEllipses = true;
opts.testEllipses =
opts.testTextExtent =
opts.testPartialTextExtents = true;
}
opts.usePaint = parser.Found("paint");