mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / storage / ndb / test / include / NdbTimer.hpp
blobb09213db1f0a1390a1e05c20e448f202604b657f
1 /* Copyright (c) 2003-2005 MySQL AB
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
16 #ifndef NDBTIMER_H
17 #define NDBTIMER_H
19 #include <NdbTick.h>
20 #include <NdbOut.hpp>
22 //
23 // Class used for measuring time and priting the results
24 //
25 // Currently measures time in milliseconds
26 //
28 class NdbTimer
30 public:
32 NdbTimer();
33 ~NdbTimer() {};
35 void doStart();
36 void doStop();
37 void doReset();
38 NDB_TICKS elapsedTime();
39 void printTransactionStatistics(const char* text,
40 int numTransactions,
41 int numOperations);
42 void printTestTimer(int numLoops,
43 int numRecords);
44 void printTotalTime(void);
45 private:
46 NDB_TICKS startTime;
47 NDB_TICKS stopTime;
50 inline NdbTimer::NdbTimer(){
51 doReset();
54 inline void NdbTimer::doReset(void){
55 startTime = 0;
56 stopTime = 0;
59 inline void NdbTimer::doStart(void){
60 startTime = NdbTick_CurrentMillisecond();
63 inline void NdbTimer::doStop(void){
64 stopTime = NdbTick_CurrentMillisecond();
67 inline NDB_TICKS NdbTimer::elapsedTime(void){
68 return (stopTime - startTime);
71 inline void NdbTimer::printTransactionStatistics(const char* text,
72 int numTransactions,
73 int numOperations){
75 // Convert to Uint32 in order to be able to print it to screen
76 Uint32 lapTime = (Uint32)elapsedTime();
77 ndbout_c("%i transactions, %i %s total time = %d ms\nAverage %f ms/transaction, %f ms/%s.\n%f transactions/second, %f %ss/second.\n",
78 numTransactions, numTransactions*numOperations, text, lapTime,
79 ((double)lapTime/numTransactions), ((double)lapTime/(numTransactions*numOperations)), text,
80 1000.0/((double)lapTime/numOperations), 1000.0/((double)lapTime/(numTransactions*numOperations)), text);
85 inline void NdbTimer::printTestTimer(int numLoops,
86 int numRecords){
87 // Convert to Uint32 in order to be able to print it to screen
88 Uint32 lapTime = (Uint32)elapsedTime();
89 ndbout_c("%i loop * %i records, total time = %d ms\nAverage %f ms/loop, %f ms/record.\n%f looop/second, %f records/second.\n",
90 numLoops, numRecords, lapTime,
91 ((double)lapTime/numLoops), ((double)lapTime/(numLoops*numRecords)),
92 1000.0/((double)lapTime/numLoops), 1000.0/((double)lapTime/(numLoops*numRecords)));
96 inline void NdbTimer::printTotalTime(void){
97 // Convert to Uint32 in order to be able to print it to screen
98 Uint32 lapTime = (Uint32)elapsedTime();
99 Uint32 secTime = lapTime/1000;
100 ndbout_c("Total time : %d seconds (%d ms)\n", secTime, lapTime);
108 #endif