diff --git a/Help/manual/cmake.1.rst b/Help/manual/cmake.1.rst index 76dc883d3842b1cfaaec174fd7920d346c4a1003..b72979028c9d05b688e5deb16903236ab7c16cc4 100644 --- a/Help/manual/cmake.1.rst +++ b/Help/manual/cmake.1.rst @@ -1196,7 +1196,7 @@ Available commands are: .. option:: time [...] - Run command and display elapsed time. + Run ```` 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 21d0cc935c6d132971544e91f1fc8d42b79c5a3b..d57b78b02559386da763a39f20bbcf5aba7dbf8e 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -50,10 +50,10 @@ #endif #include +#include #include #include #include -#include #include #include #include @@ -1104,27 +1104,13 @@ int cmcmd::ExecuteCMakeCommand(std::vector const& args, if (args[1] == "time" && args.size() > 2) { std::vector 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(CLOCKS_PER_SEC); - std::cout << "Elapsed time: " - << static_cast(time_finish - time_start) << " s. (time)" - << ", " - << static_cast(clock_finish - clock_start) / - clocks_per_sec - << " s. (clock)" - << "\n"; + std::chrono::duration 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 a51446a67e1114899bc407c1fb9869d1894f9413..1a5e13479befb3327697ef14b86d9e3072476ddc 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\): [^ ]*$