timex.cpp 1.0 KB

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