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