Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
biastimeit.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #include <stdlib.h>
26 #include <iostream>
27 #include <string>
28 
29 #include <Base/Debug/TimeMeasure.hh>
30 
31 using namespace std;
32 using namespace BIAS;
33 
34 /**
35  @file
36  @ingroup g_tools
37  @brief Helper to emulate the Unix "time" command on WIN32 platforms,
38  Measure the duration of the execution of a command=timean application run,
39  You may want to use TimeThis.exe from MS Resource Kit, see biastimeit.cpp
40  @author Jan Woetzel 2005
41 */
42 int main(int argc, char** argv)
43 {
44  if (argc<=1){
45  cout<<"usage: "<<endl;
46  if (argc>0) cout<<argv[0]<<" ";
47  cout<<"<application.exe> [<parameters>] "<<endl;
48  cout<<"example: timeit mapp.exe -myarg1"<<endl;
49  return -1;
50  }
51  // variables:
52  int result = 0;
53  string command="";
54  TimeMeasure timer1;
55 
56  // create command:
57  for (int i=1; i<argc; i++)
58  {
59  command+=argv[i];
60  command+= " "; // delimiter
61  }
62  //cout<<"overhead: "<<timer1.MeasureOverhead()<<endl;
63  cout<<"timing: "<<command<<endl;
64 
65  // run timed application as system call:
66  timer1.Start();
67  result = system( command.c_str() );
68 
69 
70  //{ // timed code
71  // double d(1);
72  // for (unsigned int a=0; a< (unsigned int)(5.0* 4000./5.); a++){
73  // for (unsigned int b=0; b<10000; b++){
74  // d+=sin(1.0+1.1*d);
75  // d-=cos(2.0+1.2*d);
76  // }
77  // }
78  // Sleep(5000);
79  //}
80 
81  timer1.Stop();
82 
83  if (result!=0){
84  cout<<"could not run, result="<<result<<endl;
85  return -2;
86  } else {
87  cout<<"timing successful. "<<endl;
88  // display final timing result:
89  timer1.Print(cout);
90  }
91  return 0;
92 }
void Print(std::ostream &os=std::cout) const
class TimeMeasure contains functions for timing real time and cpu time.
Definition: TimeMeasure.hh:111