summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorscivision <scivision@users.noreply.github.com>2023-02-15 08:54:02 -0500
committerscivision <scivision@users.noreply.github.com>2023-02-15 10:53:14 -0500
commit848f7b0a81b09ef7fa73e842222e969ecab5e8c2 (patch)
tree56e12d5517207974b4fbf16539678b18ce0c4d25
parent37f068083ba53e4140e5660a82bda9708e53c356 (diff)
downloadcmake-848f7b0a81b09ef7fa73e842222e969ecab5e8c2.tar.gz
cmake -E time: use C++11 chrono and better format output
fixes #24415
-rw-r--r--Source/cmcmd.cxx24
-rw-r--r--Tests/RunCMake/CommandLine/E_time-stdout.txt2
2 files changed, 6 insertions, 20 deletions
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx
index 21d0cc935c..d57b78b025 100644
--- a/Source/cmcmd.cxx
+++ b/Source/cmcmd.cxx
@@ -50,10 +50,10 @@
#endif
#include <array>
+#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <cstring>
-#include <ctime>
#include <iostream>
#include <memory>
#include <sstream>
@@ -1104,27 +1104,13 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
if (args[1] == "time" && args.size() > 2) {
std::vector<std::string> command(args.begin() + 2, args.end());
- clock_t clock_start;
- clock_t clock_finish;
- time_t time_start;
- time_t time_finish;
-
- time(&time_start);
- clock_start = clock();
int ret = 0;
+ auto time_start = std::chrono::steady_clock::now();
cmSystemTools::RunSingleCommand(command, nullptr, nullptr, &ret);
+ auto time_finish = std::chrono::steady_clock::now();
- clock_finish = clock();
- time(&time_finish);
-
- double clocks_per_sec = static_cast<double>(CLOCKS_PER_SEC);
- std::cout << "Elapsed time: "
- << static_cast<long>(time_finish - time_start) << " s. (time)"
- << ", "
- << static_cast<double>(clock_finish - clock_start) /
- clocks_per_sec
- << " s. (clock)"
- << "\n";
+ std::chrono::duration<double> time_elapsed = time_finish - time_start;
+ std::cout << "Elapsed time (seconds): " << time_elapsed.count() << "\n";
return ret;
}
diff --git a/Tests/RunCMake/CommandLine/E_time-stdout.txt b/Tests/RunCMake/CommandLine/E_time-stdout.txt
index a51446a67e..1a5e13479b 100644
--- a/Tests/RunCMake/CommandLine/E_time-stdout.txt
+++ b/Tests/RunCMake/CommandLine/E_time-stdout.txt
@@ -1,3 +1,3 @@
^hello world
-Elapsed time: [^
+Elapsed time \(seconds\): [^
]*$