summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastien Barre <sebastien.barre@kitware.com>2002-04-11 22:17:33 (GMT)
committerSebastien Barre <sebastien.barre@kitware.com>2002-04-11 22:17:33 (GMT)
commit23e1a28276b8fcfa6bf586ff1bd348a760fe693e (patch)
treeaddfc5d23b643f68763ac69a83f2d15ba037146e
parent789267c94903f23d231e16de6ff50a2926dcf8e4 (diff)
downloadCMake-23e1a28276b8fcfa6bf586ff1bd348a760fe693e.zip
CMake-23e1a28276b8fcfa6bf586ff1bd348a760fe693e.tar.gz
CMake-23e1a28276b8fcfa6bf586ff1bd348a760fe693e.tar.bz2
can be used to time commands (time() & clock())
-rw-r--r--Source/ccommand.cxx42
1 files changed, 38 insertions, 4 deletions
diff --git a/Source/ccommand.cxx b/Source/ccommand.cxx
index 640188c..00893e6 100644
--- a/Source/ccommand.cxx
+++ b/Source/ccommand.cxx
@@ -17,6 +17,7 @@
#include "cmMakefile.h"
#include "cmSystemTools.h"
+#include "time.h"
void CMakeCommandUsage(const char* program)
{
@@ -29,11 +30,12 @@ void CMakeCommandUsage(const char* program)
errorStream
<< "Usage: " << program << " [command] [arguments ...]\n"
<< "Available commands: \n"
- << " copy file destination - copy file to destination (either file or directory)\n"
- << " remove file1 file2 ... - remove the file(s)\n"
+ << " copy file destination - copy file to destination (either file or directory)\n"
+ << " remove file1 file2 ... - remove the file(s)\n"
+ << " time command [args] ... - run command and return elapsed time\n"
#if defined(_WIN32) && !defined(__CYGWIN__)
- << " write_regv key value - write registry value\n"
- << " delete_regv key - delete registry value\n"
+ << " write_regv key value - write registry value\n"
+ << " delete_regv key - delete registry value\n"
#endif
<< std::ends;
@@ -74,6 +76,38 @@ int main(int ac, char** av)
return 0;
}
+ // Clock command
+ else if (args[1] == "time" && args.size() > 2)
+ {
+ std::string command = args[2];
+ std::string output;
+ for (std::string::size_type cc = 3; cc < args.size(); cc ++)
+ {
+ command += " ";
+ command += args[cc];
+ }
+
+ clock_t clock_start, clock_finish;
+ time_t time_start, time_finish;
+
+ time(&time_start);
+ clock_start = clock();
+
+ cmSystemTools::RunCommand(command.c_str(), output, 0, false);
+
+ clock_finish = clock();
+ time(&time_finish);
+
+ double clocks_per_sec = (double)CLOCKS_PER_SEC;
+ std::cout << "Elapsed time: "
+ << (time_finish - time_start) << " s. (time)"
+ << ", "
+ << (double)(clock_finish - clock_start) / clocks_per_sec
+ << " s. (clock)"
+ << "\n";
+ return 0;
+ }
+
#if defined(_WIN32) && !defined(__CYGWIN__)
// Write registry value
else if (args[1] == "write_regv" && args.size() > 3)