summaryrefslogtreecommitdiffstats
path: root/raslib/test/test_rmdebug.cc
blob: c6f29ca3671d4787d063ac0305d0fac4aa9be454 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
* This file is part of rasdaman community.
*
* Rasdaman community is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Rasdaman community is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with rasdaman community.  If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
rasdaman GmbH.
*
* For more information please see <http://www.rasdaman.org>
* or contact Peter Baumann via <baumann@rasdaman.com>.
*/
/*************************************************************
 *
 * SOURCE: test_rmdebug.cc
 *
 * MODULE: raslib
 *
 * PURPOSE:
 *
 * COMMENTS:
 *
 ************************************************************/

#include <iostream>
#include "raslib/rmdebug.hh"

#include "raslib/rminit.hh"

// number of repetitions for performance tests
static const int repeat = 100000;

RMINITGLOBALS('C')
   
void testFunc1()
{
   RMDebug localRMDebug = RMDebug("Class1", "testFunc1", "Module1",
				  __FILE__, __LINE__);
}

void testFunc2(int reclevel)
{
   RMDebug localRMDebug = RMDebug("Class1", "testFunc2", "Module1",
				  __FILE__, __LINE__);

   if(reclevel > 1)
     testFunc2(reclevel - 1);
}

void testFunc3(void)
{
  RMDebug localRMDebug("Class1", "testFunc3", "server",
		       __FILE__, __LINE__);

  RMDBGMOUT( 2, RMDebug::module_server, NULL, "D: testing 1" );
  RMDBGMOUT( 3, RMDebug::module_server, "Class1", "D: testing 2" );
  RMDBGMINOUT( 4, RMDebug::module_server, "Class1", "D: testing 3" );
}

void testFunc4(int reclevel)
{
  RMDebug localRMDebug(1, "Class2", "testFunc4", RMDebug::module_raslib,
		       __FILE__, __LINE__);

  if (reclevel > 1)
    testFunc4(reclevel - 1);
}

// this was used to test correctness

void oldMain()
{
  int i;

  for(i = 1; i<=5; i++)
    testFunc1();

  testFunc2(5);

  testFunc3();

  testFunc4(4);

  cout << "Test of RMTimer" << endl;
 
  cout << "The following should hold approximately: timer2 + timer3 = timer1" << endl << endl;

  RMTimer* timer1 = new RMTimer("main","timer1");
  RMTimer* timer2 = new RMTimer("main","timer2");

  timer2->pause();

  RMTimer* timer3 = new RMTimer("main","timer3");
  for( long busy=0; busy <= 50000000; busy++ );
  delete timer3;

  timer2->resume();

  for( busy=0; busy <= 30000000; busy++ );

  delete timer2;
  delete timer1;

  cout << "Benchmark level set to " << RManBenchmark << endl;

  RMInit::bmOut << "test output in benchmark stream" << endl;
}

double testStatic(double dummy)
{
  RMTIMER("test_rmdebug", "testStatic");

  for(int i=0; i<repeat; i++)
    dummy = dummy*4711.4712;
  return dummy;
}

double testDynamic(double dummy)
{
#ifdef RMANBENCHMARK
  RMTimer* localRMTimer = 0;

  if( RManBenchmark >= 3 )
    localRMTimer = new RMTimer("test_rmdebug", "testDynamic");
#endif

  for(int i=0; i<repeat; i++)
    dummy = dummy*4711.4712;

#ifdef RMANBENCHMARK
  if( localRMTimer ) delete localRMTimer;
#endif

  return dummy;
}

// Evaluating time needed for measurement with different uses
// of RMTimer.

void testPerf()
{
  double dummy = 3.14;

  cout << "Testing dynamic RMTimer vs. static RMTimer." << endl;

  // to put in cache
  dummy = testStatic(dummy);
  cout << "Static:" << endl;
  dummy = testStatic(dummy);

  // to put in cache
  dummy = testDynamic(dummy);
  cout << "Dynamic:" << endl;
  dummy = testDynamic(dummy);
}

int main()
{
  RMDebug::initRMDebug();
  RManBenchmark = 4;
  RMInit::bmOut = cout.rdbuf();

  oldMain();
  // testPerf();

  return 0;
}