benchmark/random_bench.cc
author kpeter
Tue, 05 Feb 2008 11:23:23 +0000
changeset 2562 27c54b7f4f1d
parent 2391 14a343be7a5a
permissions -rw-r--r--
Improvements and fixes in dim2.h.

- Several doc improvements.
- Fix BoundingBox::operator& implementation.
alpar@2391
     1
/* -*- C++ -*-
alpar@2391
     2
 *
alpar@2391
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@2391
     4
 *
alpar@2553
     5
 * Copyright (C) 2003-2008
alpar@2391
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@2391
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@2391
     8
 *
alpar@2391
     9
 * Permission to use, modify and distribute this software is granted
alpar@2391
    10
 * provided that this copyright notice appears in all copies. For
alpar@2391
    11
 * precise terms see the accompanying LICENSE file.
alpar@2391
    12
 *
alpar@2391
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@2391
    14
 * express or implied, and with no claim as to its suitability for any
alpar@2391
    15
 * purpose.
alpar@2391
    16
 *
alpar@2391
    17
 */
alpar@2391
    18
alpar@2244
    19
#include<stdlib.h>
alpar@2244
    20
#include<lemon/random.h>
alpar@2244
    21
#include<lemon/time_measure.h>
alpar@2244
    22
alpar@2244
    23
using namespace lemon;
alpar@2244
    24
alpar@2244
    25
void f_no() 
alpar@2244
    26
{
alpar@2244
    27
}
alpar@2244
    28
alpar@2244
    29
inline void f_noi() 
alpar@2244
    30
{
alpar@2244
    31
}
alpar@2244
    32
alpar@2244
    33
inline void f_i() 
alpar@2244
    34
{
alpar@2244
    35
  static int r;  
alpar@2244
    36
  r=5;
alpar@2244
    37
}
alpar@2244
    38
alpar@2244
    39
inline void f_l() 
alpar@2244
    40
{
alpar@2244
    41
  static long int r;
alpar@2244
    42
  r=5;
alpar@2244
    43
}
alpar@2244
    44
alpar@2244
    45
inline void f_d() 
alpar@2244
    46
{
alpar@2244
    47
  static double r;
alpar@2244
    48
  r=5;
alpar@2244
    49
}
alpar@2244
    50
alpar@2244
    51
inline void f_rand() 
alpar@2244
    52
{
alpar@2244
    53
  static int r;  
alpar@2244
    54
  r=rand();
alpar@2244
    55
}
alpar@2244
    56
alpar@2244
    57
inline void f_random() 
alpar@2244
    58
{
alpar@2244
    59
  static long int r;
alpar@2244
    60
  r=random();
alpar@2244
    61
}
alpar@2244
    62
alpar@2244
    63
inline void f_drand48() 
alpar@2244
    64
{
alpar@2244
    65
  static double r;
alpar@2244
    66
  r=drand48();
alpar@2244
    67
}
alpar@2244
    68
alpar@2244
    69
inline void f_rnd_d() 
alpar@2244
    70
{
alpar@2244
    71
  static double r;
alpar@2244
    72
  r=rnd();
alpar@2244
    73
}
alpar@2244
    74
inline void f_rnd_int1000() 
alpar@2244
    75
{
alpar@2244
    76
  static int r;
alpar@2244
    77
  r=rnd[1000];
alpar@2244
    78
}
alpar@2244
    79
inline void f_rnd_bool() 
alpar@2244
    80
{
alpar@2244
    81
  static bool r;
alpar@2244
    82
  r=rnd.boolean();
alpar@2244
    83
}
alpar@2244
    84
alpar@2244
    85
// inline void f_() 
alpar@2244
    86
// {
alpar@2244
    87
//   static double r;
alpar@2244
    88
//   r=;
alpar@2244
    89
// }
alpar@2244
    90
alpar@2244
    91
int main()
alpar@2244
    92
{
alpar@2244
    93
  TimeStamp full;
alpar@2244
    94
  TimeStamp t;
alpar@2244
    95
  unsigned int n;
alpar@2244
    96
  
alpar@2244
    97
  const double TEST_DURATION=10;
alpar@2244
    98
alpar@2244
    99
  t=runningTimeTest(f_no,2,&n,&full);
alpar@2244
   100
alpar@2244
   101
  t=runningTimeTest(f_no,TEST_DURATION,&n,&full); 
alpar@2244
   102
  std::cout << "EMPTY:         ";
alpar@2244
   103
  std::cout << t.userTime() << " (" << n << " tests)\n";
alpar@2244
   104
  
alpar@2244
   105
  t=runningTimeTest(f_noi,TEST_DURATION,&n,&full);
alpar@2244
   106
  std::cout << "INLINED EMPTY: ";
alpar@2244
   107
  std::cout << t.userTime() << " (" << n << " tests)\n";
alpar@2244
   108
  
alpar@2244
   109
  TimeStamp ti=t=runningTimeTest(f_i,TEST_DURATION,&n,&full);
alpar@2244
   110
  std::cout << "INT COPY:      ";
alpar@2244
   111
  std::cout << t.userTime() << " (" << n << " tests)\n";
alpar@2244
   112
  
alpar@2244
   113
  TimeStamp tl=t=runningTimeTest(f_l,TEST_DURATION,&n,&full);
alpar@2244
   114
  std::cout << "LONG COPY:     ";
alpar@2244
   115
  std::cout << t.userTime() << " (" << n << " tests)\n";
alpar@2244
   116
  
alpar@2244
   117
  TimeStamp td=t=runningTimeTest(f_d,TEST_DURATION,&n,&full);
alpar@2244
   118
  std::cout << "DOUBLE COPY:   ";
alpar@2244
   119
  std::cout << t.userTime() << " (" << n << " tests)\n";
alpar@2244
   120
  
alpar@2244
   121
  t=runningTimeTest(f_rand,TEST_DURATION,&n,&full);
alpar@2244
   122
  std::cout << "rand():        ";
alpar@2244
   123
  std::cout << (t-ti).userTime() << " (" << n << " tests)\n";
alpar@2244
   124
  
alpar@2244
   125
  t=runningTimeTest(f_random,TEST_DURATION,&n,&full);
alpar@2244
   126
  std::cout << "random():      ";
alpar@2244
   127
  std::cout << (t-tl).userTime() << " (" << n << " tests)\n";
alpar@2244
   128
  
alpar@2244
   129
  t=runningTimeTest(f_drand48,TEST_DURATION,&n,&full);
alpar@2244
   130
  std::cout << "drand48():     ";
alpar@2244
   131
  std::cout << (t-td).userTime() << " (" << n << " tests)\n";
alpar@2244
   132
  
alpar@2244
   133
  t=runningTimeTest(f_rnd_d,TEST_DURATION,&n,&full);
alpar@2244
   134
  std::cout << "rnd():         ";
alpar@2244
   135
  std::cout << (t-td).userTime() << " (" << n << " tests)\n";
alpar@2244
   136
  
alpar@2244
   137
  t=runningTimeTest(f_rnd_int1000,TEST_DURATION,&n,&full);
alpar@2244
   138
  std::cout << "rnd[1000]:     ";
alpar@2244
   139
  std::cout << (t-ti).userTime() << " (" << n << " tests)\n";
alpar@2244
   140
  
alpar@2244
   141
  t=runningTimeTest(f_rnd_bool,TEST_DURATION,&n,&full);
alpar@2244
   142
  std::cout << "rnd.boolean(): ";
alpar@2244
   143
  std::cout << (t-ti).userTime() << " (" << n << " tests)\n";
alpar@2244
   144
  
alpar@2244
   145
//   t=runningTimeTest(f_,TEST_DURATION,&n,&full);
alpar@2244
   146
//   std::cout << "\n";
alpar@2244
   147
//   std::cout << t << " (" << n << " tests)\n";
alpar@2244
   148
//   std::cout << "Total: " << full << "\n\n";
alpar@2244
   149
  
alpar@2244
   150
  return 0;
alpar@2244
   151
}