Crazy Eddie's GUI System  ${CEGUI_VERSION}
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
PerformanceTest.h
1 /***********************************************************************
2  * created: Fri Aug 15 2014
3  * author: Timotei Dolean <timotei21@gmail.com>
4  *************************************************************************/
5 /***************************************************************************
6  * Copyright (C) 2004 - 2014 Paul D Turner & The CEGUI Development Team
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  ***************************************************************************/
27 #ifndef _CEGUITestsPerformanceTest_h_
28 #define _CEGUITestsPerformanceTest_h_
29 
30 #include <boost/timer/timer.hpp>
31 #include <fstream>
32 
33 #include "CEGUI/WindowManager.h"
34 
43 {
44 public:
45  explicit PerformanceTest(CEGUI::String test_name) : d_testName(test_name) { }
46  virtual ~PerformanceTest() {}
47 
48 
49  CEGUI::String d_testName;
50 
51  void execute()
52  {
53  std::cout
54  << "Running performance test " << d_testName << "..." << std::endl;
55 
56  boost::timer::auto_cpu_timer timer;
57 
58  doTest();
59 
60  logRunningTime(boost::timer::format(timer.elapsed(), timer.places(), "%u, %w"));
61  }
62 
63 protected:
64  virtual void doTest() = 0;
65 
66 private:
67  void logRunningTime(std::string result)
68  {
69  std::ofstream fout("performance-test-results.csv",
70  std::ofstream::out | std::ofstream::app);
71 
72  // fill column names if file is empty.
73  fout.seekp(0, std::ios::end);
74  const std::streamoff length = fout.tellp();
75  if (length == 0)
76  {
77  fout << "test name, user time (seconds), wall time (seconds)" << std::endl;
78  }
79 
80  fout << d_testName << ", " << result << std::endl;
81  fout.close();
82  }
83 };
84 
91 template<typename TWindow>
93 {
94 public:
95  WindowPerformanceTest(CEGUI::String window_type, CEGUI::String renderer) :
96  PerformanceTest(window_type),
97  d_window(0)
98  {
99  d_window = static_cast<TWindow*>(
100  CEGUI::WindowManager::getSingleton().createWindow(
101  window_type, window_type + "-perf-test"));
102  d_window->setWindowRenderer(renderer);
103  }
104 
105  virtual void render()
106  {
107  d_window->render();
108  }
109 
110  TWindow* d_window;
111 };
112 
121 template<typename TWindow>
123 {
124 public:
125  BaseListPerformanceTest(CEGUI::String windowType, CEGUI::String renderer) :
126  WindowPerformanceTest<TWindow>(windowType, renderer)
127  {
128  }
129 
130  virtual void doTest()
131  {
132  addItemsWithRender(500);
133 
134  clearItems();
135  this->render();
136 
137  addItemsWithRender(1000);
138 
139  deleteFirstItems(150);
140  this->render();
141 
142  for (size_t step = 0; step < 17; ++step)
143  {
144  deleteFirstItems(3);
145  this->render();
146  }
147 
148  deleteLastItems(123);
149  this->render();
150 
151  clearItems();
152  this->render();
153 
154  addItemsWithRender(100);
155 
156  for (size_t i = 0; i < 50; ++i)
157  {
158  addItems(1, 50);
159  this->render();
160  }
161 
162  sortItems();
163  this->render();
164  }
165 
167  virtual void addItemsWithRender(size_t count)
168  {
169  for (size_t i = 0; i < count; ++i)
170  {
171  addItems(1);
172  this->render();
173  }
174  }
175 
176  virtual void clearItems() = 0;
177  virtual void addItems(size_t count) = 0;
178  virtual void addItems(size_t count, size_t at_position) = 0;
179  virtual void deleteFirstItems(size_t count) = 0;
180  virtual void deleteLastItems(size_t count) = 0;
181  virtual void sortItems() = 0;
182 };
183 
184 #endif
This represents a generic test made on list widgets. It adds items, deletes some, then inserts items ...
Definition: PerformanceTest.h:122
Window * createWindow(const String &type, const String &name="")
Creates a new Window object of the specified type, and gives it the specified unique name...
Definition: WindowManager.cpp:96
General structure of a performance test.
Definition: PerformanceTest.h:42
virtual void addItemsWithRender(size_t count)
Adds the specified number of items, rendering after each addition.
Definition: PerformanceTest.h:167
Generic test on a Window. It will automatically create the specified window type and set the renderer...
Definition: PerformanceTest.h:92
String class used within the GUI system.
Definition: cegui/include/CEGUI/String.h:62