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