benchmark/random_bench.cc
author alpar
Mon, 30 Oct 2006 16:19:18 +0000
changeset 2274 432d0469a87e
child 2391 14a343be7a5a
permissions -rw-r--r--
Turn off 32 bit only tests, cont'd.
alpar@2244
     1
#include<stdlib.h>
alpar@2244
     2
#include<lemon/random.h>
alpar@2244
     3
#include<lemon/time_measure.h>
alpar@2244
     4
alpar@2244
     5
using namespace lemon;
alpar@2244
     6
alpar@2244
     7
void f_no() 
alpar@2244
     8
{
alpar@2244
     9
}
alpar@2244
    10
alpar@2244
    11
inline void f_noi() 
alpar@2244
    12
{
alpar@2244
    13
}
alpar@2244
    14
alpar@2244
    15
inline void f_i() 
alpar@2244
    16
{
alpar@2244
    17
  static int r;  
alpar@2244
    18
  r=5;
alpar@2244
    19
}
alpar@2244
    20
alpar@2244
    21
inline void f_l() 
alpar@2244
    22
{
alpar@2244
    23
  static long int r;
alpar@2244
    24
  r=5;
alpar@2244
    25
}
alpar@2244
    26
alpar@2244
    27
inline void f_d() 
alpar@2244
    28
{
alpar@2244
    29
  static double r;
alpar@2244
    30
  r=5;
alpar@2244
    31
}
alpar@2244
    32
alpar@2244
    33
inline void f_rand() 
alpar@2244
    34
{
alpar@2244
    35
  static int r;  
alpar@2244
    36
  r=rand();
alpar@2244
    37
}
alpar@2244
    38
alpar@2244
    39
inline void f_random() 
alpar@2244
    40
{
alpar@2244
    41
  static long int r;
alpar@2244
    42
  r=random();
alpar@2244
    43
}
alpar@2244
    44
alpar@2244
    45
inline void f_drand48() 
alpar@2244
    46
{
alpar@2244
    47
  static double r;
alpar@2244
    48
  r=drand48();
alpar@2244
    49
}
alpar@2244
    50
alpar@2244
    51
inline void f_rnd_d() 
alpar@2244
    52
{
alpar@2244
    53
  static double r;
alpar@2244
    54
  r=rnd();
alpar@2244
    55
}
alpar@2244
    56
inline void f_rnd_int1000() 
alpar@2244
    57
{
alpar@2244
    58
  static int r;
alpar@2244
    59
  r=rnd[1000];
alpar@2244
    60
}
alpar@2244
    61
inline void f_rnd_bool() 
alpar@2244
    62
{
alpar@2244
    63
  static bool r;
alpar@2244
    64
  r=rnd.boolean();
alpar@2244
    65
}
alpar@2244
    66
alpar@2244
    67
// inline void f_() 
alpar@2244
    68
// {
alpar@2244
    69
//   static double r;
alpar@2244
    70
//   r=;
alpar@2244
    71
// }
alpar@2244
    72
alpar@2244
    73
int main()
alpar@2244
    74
{
alpar@2244
    75
  TimeStamp full;
alpar@2244
    76
  TimeStamp t;
alpar@2244
    77
  unsigned int n;
alpar@2244
    78
  
alpar@2244
    79
  const double TEST_DURATION=10;
alpar@2244
    80
alpar@2244
    81
  t=runningTimeTest(f_no,2,&n,&full);
alpar@2244
    82
alpar@2244
    83
  t=runningTimeTest(f_no,TEST_DURATION,&n,&full); 
alpar@2244
    84
  std::cout << "EMPTY:         ";
alpar@2244
    85
  std::cout << t.userTime() << " (" << n << " tests)\n";
alpar@2244
    86
  
alpar@2244
    87
  t=runningTimeTest(f_noi,TEST_DURATION,&n,&full);
alpar@2244
    88
  std::cout << "INLINED EMPTY: ";
alpar@2244
    89
  std::cout << t.userTime() << " (" << n << " tests)\n";
alpar@2244
    90
  
alpar@2244
    91
  TimeStamp ti=t=runningTimeTest(f_i,TEST_DURATION,&n,&full);
alpar@2244
    92
  std::cout << "INT COPY:      ";
alpar@2244
    93
  std::cout << t.userTime() << " (" << n << " tests)\n";
alpar@2244
    94
  
alpar@2244
    95
  TimeStamp tl=t=runningTimeTest(f_l,TEST_DURATION,&n,&full);
alpar@2244
    96
  std::cout << "LONG COPY:     ";
alpar@2244
    97
  std::cout << t.userTime() << " (" << n << " tests)\n";
alpar@2244
    98
  
alpar@2244
    99
  TimeStamp td=t=runningTimeTest(f_d,TEST_DURATION,&n,&full);
alpar@2244
   100
  std::cout << "DOUBLE COPY:   ";
alpar@2244
   101
  std::cout << t.userTime() << " (" << n << " tests)\n";
alpar@2244
   102
  
alpar@2244
   103
  t=runningTimeTest(f_rand,TEST_DURATION,&n,&full);
alpar@2244
   104
  std::cout << "rand():        ";
alpar@2244
   105
  std::cout << (t-ti).userTime() << " (" << n << " tests)\n";
alpar@2244
   106
  
alpar@2244
   107
  t=runningTimeTest(f_random,TEST_DURATION,&n,&full);
alpar@2244
   108
  std::cout << "random():      ";
alpar@2244
   109
  std::cout << (t-tl).userTime() << " (" << n << " tests)\n";
alpar@2244
   110
  
alpar@2244
   111
  t=runningTimeTest(f_drand48,TEST_DURATION,&n,&full);
alpar@2244
   112
  std::cout << "drand48():     ";
alpar@2244
   113
  std::cout << (t-td).userTime() << " (" << n << " tests)\n";
alpar@2244
   114
  
alpar@2244
   115
  t=runningTimeTest(f_rnd_d,TEST_DURATION,&n,&full);
alpar@2244
   116
  std::cout << "rnd():         ";
alpar@2244
   117
  std::cout << (t-td).userTime() << " (" << n << " tests)\n";
alpar@2244
   118
  
alpar@2244
   119
  t=runningTimeTest(f_rnd_int1000,TEST_DURATION,&n,&full);
alpar@2244
   120
  std::cout << "rnd[1000]:     ";
alpar@2244
   121
  std::cout << (t-ti).userTime() << " (" << n << " tests)\n";
alpar@2244
   122
  
alpar@2244
   123
  t=runningTimeTest(f_rnd_bool,TEST_DURATION,&n,&full);
alpar@2244
   124
  std::cout << "rnd.boolean(): ";
alpar@2244
   125
  std::cout << (t-ti).userTime() << " (" << n << " tests)\n";
alpar@2244
   126
  
alpar@2244
   127
//   t=runningTimeTest(f_,TEST_DURATION,&n,&full);
alpar@2244
   128
//   std::cout << "\n";
alpar@2244
   129
//   std::cout << t << " (" << n << " tests)\n";
alpar@2244
   130
//   std::cout << "Total: " << full << "\n\n";
alpar@2244
   131
  
alpar@2244
   132
  return 0;
alpar@2244
   133
}