test/time_measure_test.cc
changeset 124 ae7785fe8431
child 171 02f4d5d9bfd7
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/time_measure_test.cc	Sat Apr 12 20:38:51 2008 +0100
     1.3 @@ -0,0 +1,63 @@
     1.4 +/* -*- C++ -*-
     1.5 + *
     1.6 + * This file is a part of LEMON, a generic C++ optimization library
     1.7 + *
     1.8 + * Copyright (C) 2003-2008
     1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.11 + *
    1.12 + * Permission to use, modify and distribute this software is granted
    1.13 + * provided that this copyright notice appears in all copies. For
    1.14 + * precise terms see the accompanying LICENSE file.
    1.15 + *
    1.16 + * This software is provided "AS IS" with no warranty of any kind,
    1.17 + * express or implied, and with no claim as to its suitability for any
    1.18 + * purpose.
    1.19 + *
    1.20 + */
    1.21 +
    1.22 +#include <lemon/time_measure.h>
    1.23 +
    1.24 +///\file \brief Test cases for time_measure.h
    1.25 +///
    1.26 +///\todo To be extended
    1.27 +
    1.28 +
    1.29 +using namespace lemon;
    1.30 +
    1.31 +void f() 
    1.32 +{
    1.33 +  double d=0;
    1.34 +  for(int i=0;i<1000;i++)
    1.35 +    d+=0.1;
    1.36 +}
    1.37 +
    1.38 +void g() 
    1.39 +{
    1.40 +  static Timer T;
    1.41 +  
    1.42 +  for(int i=0;i<1000;i++)
    1.43 +    TimeStamp x(T);
    1.44 +}
    1.45 +
    1.46 +int main()
    1.47 +{
    1.48 +  Timer T;
    1.49 +  unsigned int n;
    1.50 +  for(n=0;T.realTime()<1.0;n++) ;
    1.51 +  std::cout << T << " (" << n << " time queries)\n";
    1.52 +  T.restart();
    1.53 +  while(T.realTime()<2.0) ;
    1.54 +  std::cout << T << '\n';
    1.55 +  TimeStamp full;
    1.56 +  TimeStamp t;
    1.57 +  t=runningTimeTest(f,1,&n,&full);
    1.58 +  std::cout << t << " (" << n << " tests)\n";
    1.59 +  std::cout << "Total: " << full << "\n";
    1.60 +  
    1.61 +  t=runningTimeTest(g,1,&n,&full);
    1.62 +  std::cout << t << " (" << n << " tests)\n";
    1.63 +  std::cout << "Total: " << full << "\n";
    1.64 +  
    1.65 +  return 0;
    1.66 +}