1 // timex: timed execution program ------------------------------------------// 2 3 // Copyright Beman Dawes 2007 4 5 // Distributed under the Boost Software License, Version 1.0. 6 // See http://www.boost.org/LICENSE_1_0.txt 7 8 // See http://www.boost.org/libs/timer for documentation. 9 10 #include <boost/timer/timer.hpp> 11 #include <cstdlib> 12 #include <string> 13 #include <iostream> 14 main(int argc,char * argv[])15int main( int argc, char * argv[] ) 16 { 17 if ( argc == 1 ) 18 { 19 std::cout << "invoke: timex [-v] command [args...]\n" 20 " command will be executed and timings displayed\n" 21 " -v option causes command and args to be displayed\n"; 22 return 1; 23 } 24 25 std::string s; 26 27 bool verbose = false; 28 if ( argc > 1 && *argv[1] == '-' && *(argv[1]+1) == 'v' ) 29 { 30 verbose = true; 31 ++argv; 32 --argc; 33 } 34 35 for ( int i = 1; i < argc; ++i ) 36 { 37 if ( i > 1 ) s += ' '; 38 s += argv[i]; 39 } 40 41 if ( verbose ) 42 { std::cout << "command: \"" << s.c_str() << "\"\n"; } 43 44 boost::timer::auto_cpu_timer t(" %ws elapsed wall-clock time\n"); 45 46 return std::system( s.c_str() ); 47 } 48