]>
git.saurik.com Git - wxWidgets.git/blob - tests/benchmarks/graphics.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Some benchmarks for measuring graphics operations performance
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows license
9 /////////////////////////////////////////////////////////////////////////////
13 #include "wx/cmdline.h"
14 #include "wx/dcclient.h"
15 #include "wx/dcmemory.h"
16 #include "wx/stopwatch.h"
18 struct GraphicsBenchmarkOptions
20 GraphicsBenchmarkOptions()
38 class GraphicsBenchmarkFrame
: public wxFrame
41 GraphicsBenchmarkFrame()
42 : wxFrame(NULL
, wxID_ANY
, "wxWidgets Graphics Benchmark")
45 wxPaintEventHandler(GraphicsBenchmarkFrame::OnPaint
));
48 SetClientSize(opts
.width
, opts
.height
);
50 BenchmarkLines("client", dc
);
52 wxBitmap
bmp(opts
.width
, opts
.height
);
54 BenchmarkLines("memory", dc2
);
58 void OnPaint(wxPaintEvent
& WXUNUSED(event
))
62 BenchmarkLines(" paint", dc
);
64 wxTheApp
->ExitMainLoop();
67 void BenchmarkLines(const char *msg
, wxDC
& dc
)
69 if ( opts
.mapMode
!= 0 )
70 dc
.SetMapMode(opts
.mapMode
);
71 if ( opts
.penWidth
!= 0 )
72 dc
.SetPen(wxPen(*wxWHITE
, opts
.penWidth
));
74 wxPrintf("Benchmarking %s DC: ", msg
);
79 for ( int n
= 0; n
< opts
.numLines
; n
++ )
81 int x1
= rand() % opts
.width
,
82 y1
= rand() % opts
.height
;
84 dc
.DrawLine(x
, y
, x1
, y1
);
90 const long t
= sw
.Time();
92 wxPrintf("%d lines done in %lums = %gus/line\n",
93 opts
.numLines
, t
, (1000. * t
)/opts
.numLines
);
97 class GraphicsBenchmarkApp
: public wxApp
100 virtual void OnInitCmdLine(wxCmdLineParser
& parser
)
102 static const wxCmdLineEntryDesc desc
[] =
104 { wxCMD_LINE_OPTION
, "m", "map-mode", "", wxCMD_LINE_VAL_NUMBER
},
105 { wxCMD_LINE_OPTION
, "p", "pen-width", "", wxCMD_LINE_VAL_NUMBER
},
106 { wxCMD_LINE_OPTION
, "w", "width", "", wxCMD_LINE_VAL_NUMBER
},
107 { wxCMD_LINE_OPTION
, "h", "height", "", wxCMD_LINE_VAL_NUMBER
},
108 { wxCMD_LINE_OPTION
, "L", "lines", "", wxCMD_LINE_VAL_NUMBER
},
111 parser
.SetDesc(desc
);
114 virtual bool OnCmdLineParsed(wxCmdLineParser
& parser
)
116 if ( parser
.Found("m", &opts
.mapMode
) &&
117 (opts
.mapMode
< 1 || opts
.mapMode
> wxMM_METRIC
) )
119 if ( parser
.Found("p", &opts
.penWidth
) && opts
.penWidth
< 1 )
121 if ( parser
.Found("w", &opts
.width
) && opts
.width
< 1 )
123 if ( parser
.Found("h", &opts
.height
) && opts
.height
< 1 )
125 if ( parser
.Found("L", &opts
.numLines
) && opts
.numLines
< 1 )
131 virtual bool OnInit()
133 if ( !wxApp::OnInit() )
136 new GraphicsBenchmarkFrame
;
142 IMPLEMENT_APP_CONSOLE(GraphicsBenchmarkApp
)