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:
@@ -64,7 +64,9 @@ struct GraphicsBenchmarkOptions
|
|||||||
testRawBitmaps =
|
testRawBitmaps =
|
||||||
testRectangles =
|
testRectangles =
|
||||||
testCircles =
|
testCircles =
|
||||||
testEllipses = false;
|
testEllipses =
|
||||||
|
testTextExtent =
|
||||||
|
testPartialTextExtents = false;
|
||||||
|
|
||||||
usePaint =
|
usePaint =
|
||||||
useClient =
|
useClient =
|
||||||
@@ -91,7 +93,9 @@ struct GraphicsBenchmarkOptions
|
|||||||
testRawBitmaps,
|
testRawBitmaps,
|
||||||
testRectangles,
|
testRectangles,
|
||||||
testCircles,
|
testCircles,
|
||||||
testEllipses;
|
testEllipses,
|
||||||
|
testTextExtent,
|
||||||
|
testPartialTextExtents;
|
||||||
|
|
||||||
bool usePaint,
|
bool usePaint,
|
||||||
useClient,
|
useClient,
|
||||||
@@ -396,6 +400,8 @@ private:
|
|||||||
BenchmarkRoundedRectangles(msg, dc);
|
BenchmarkRoundedRectangles(msg, dc);
|
||||||
BenchmarkCircles(msg, dc);
|
BenchmarkCircles(msg, dc);
|
||||||
BenchmarkEllipses(msg, dc);
|
BenchmarkEllipses(msg, dc);
|
||||||
|
BenchmarkTextExtent(msg, dc);
|
||||||
|
BenchmarkPartialTextExtents(msg, dc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetupDC(wxDC& dc)
|
void SetupDC(wxDC& dc)
|
||||||
@@ -612,6 +618,60 @@ private:
|
|||||||
opts.numIters, t, (1000. * t)/opts.numIters);
|
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)
|
void BenchmarkBitmaps(const wxString& msg, wxDC& dc)
|
||||||
{
|
{
|
||||||
if ( !opts.testBitmaps )
|
if ( !opts.testBitmaps )
|
||||||
@@ -786,6 +846,8 @@ public:
|
|||||||
{ wxCMD_LINE_SWITCH, "", "rectangles" },
|
{ wxCMD_LINE_SWITCH, "", "rectangles" },
|
||||||
{ wxCMD_LINE_SWITCH, "", "circles" },
|
{ wxCMD_LINE_SWITCH, "", "circles" },
|
||||||
{ wxCMD_LINE_SWITCH, "", "ellipses" },
|
{ wxCMD_LINE_SWITCH, "", "ellipses" },
|
||||||
|
{ wxCMD_LINE_SWITCH, "", "textextent" },
|
||||||
|
{ wxCMD_LINE_SWITCH, "", "partialtextextents" },
|
||||||
{ wxCMD_LINE_SWITCH, "", "paint" },
|
{ wxCMD_LINE_SWITCH, "", "paint" },
|
||||||
{ wxCMD_LINE_SWITCH, "", "client" },
|
{ wxCMD_LINE_SWITCH, "", "client" },
|
||||||
{ wxCMD_LINE_SWITCH, "", "memory" },
|
{ wxCMD_LINE_SWITCH, "", "memory" },
|
||||||
@@ -859,9 +921,12 @@ public:
|
|||||||
opts.testRectangles = parser.Found("rectangles");
|
opts.testRectangles = parser.Found("rectangles");
|
||||||
opts.testCircles = parser.Found("circles");
|
opts.testCircles = parser.Found("circles");
|
||||||
opts.testEllipses = parser.Found("ellipses");
|
opts.testEllipses = parser.Found("ellipses");
|
||||||
|
opts.testTextExtent = parser.Found("textextent");
|
||||||
|
opts.testPartialTextExtents = parser.Found("partialtextextents");
|
||||||
if ( !(opts.testBitmaps || opts.testImages || opts.testLines
|
if ( !(opts.testBitmaps || opts.testImages || opts.testLines
|
||||||
|| opts.testRawBitmaps || opts.testRectangles
|
|| opts.testRawBitmaps || opts.testRectangles
|
||||||
|| opts.testCircles || opts.testEllipses) )
|
|| opts.testCircles || opts.testEllipses
|
||||||
|
|| opts.testTextExtent || opts.testPartialTextExtents) )
|
||||||
{
|
{
|
||||||
// Do everything by default.
|
// Do everything by default.
|
||||||
opts.testBitmaps =
|
opts.testBitmaps =
|
||||||
@@ -870,7 +935,9 @@ public:
|
|||||||
opts.testRawBitmaps =
|
opts.testRawBitmaps =
|
||||||
opts.testRectangles =
|
opts.testRectangles =
|
||||||
opts.testCircles =
|
opts.testCircles =
|
||||||
opts.testEllipses = true;
|
opts.testEllipses =
|
||||||
|
opts.testTextExtent =
|
||||||
|
opts.testPartialTextExtents = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
opts.usePaint = parser.Found("paint");
|
opts.usePaint = parser.Found("paint");
|
||||||
|
Reference in New Issue
Block a user