diff options
author | Brad King <brad.king@kitware.com> | 2023-02-16 16:39:13 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2023-02-16 16:39:20 (GMT) |
commit | 4e54067eaa29d2a989df4da4c07a986a5f4c8552 (patch) | |
tree | 4f2e94d0501372759f10aba1d230ae68894e4736 | |
parent | c902efdb6a8481c54abb342d6ebca3d9009bae45 (diff) | |
parent | bf5512ef5160496d50d948d6c5f6391bb147fce0 (diff) | |
download | CMake-4e54067eaa29d2a989df4da4c07a986a5f4c8552.zip CMake-4e54067eaa29d2a989df4da4c07a986a5f4c8552.tar.gz CMake-4e54067eaa29d2a989df4da4c07a986a5f4c8552.tar.bz2 |
Merge topic 'cmake-E-time-chrono'
bf5512ef51 Help:cmake -E time: note overhead included
848f7b0a81 cmake -E time: use C++11 chrono and better format output
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !8209
-rw-r--r-- | Help/manual/cmake.1.rst | 2 | ||||
-rw-r--r-- | Source/cmcmd.cxx | 24 | ||||
-rw-r--r-- | Tests/RunCMake/CommandLine/E_time-stdout.txt | 2 |
3 files changed, 7 insertions, 21 deletions
diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst index 76dc883..b729790 100644 --- a/Help/manual/cmake.1.rst +++ b/Help/manual/cmake.1.rst @@ -1196,7 +1196,7 @@ Available commands are: .. option:: time <command> [<args>...] - Run command and display elapsed time. + Run ``<command>`` and display elapsed time (including overhead of CMake frontend). .. versionadded:: 3.5 The command now properly passes arguments with spaces or special characters diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 21d0cc9..d57b78b 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 a51446a..1a5e134 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\): [^ ]*$ |