chrono

Why can't I change the 'last write time' of my newly created files?

◇◆丶佛笑我妖孽 提交于 2019-12-31 05:19:05
问题 First off, I'm using Visual Studio 2015's implementation of the Filesystem library from the upcoming C++17 standard, which is based on Boost::Filesystem. Basically, what I'm trying to do is save a file's timestamp (it's "last write time"), copy that file's contents into an archive along with said timestamp, then extract that file back out and use the saved timestamp to restore the correct "last write time". // Get the file's 'last write time' and convert it into a usable integer. __int64

Measure execution time of arbitrary functions with C++14 lambda

蹲街弑〆低调 提交于 2019-12-30 09:58:14
问题 I have been excited by item 24 of Scott Meyer's book "Effective Modern C++". He mentions the possibility to write a C++14 lambda to record the time taken in an arbitrary function invocation. I am still in an early of learning C++14 features. My attempt (Main.cpp) looks like this for measuring the time of a member function call: #include <chrono> #include <iostream> auto measure = [](auto&& function, auto&&... parameters) -> decltype(function) { const std::chrono::steady_clock::time_point

What's the Difference Between floor and duration_cast?

纵然是瞬间 提交于 2019-12-30 08:15:13
问题 So in c++11 the Chrono Library provides, duration_cast: Computations are done in the widest type available and converted, as if by static_cast, to the result type only when finished And c++17's floor: Returns the greatest duration t representable in ToDuration that is less or equal to d So for all x will the result of these 2 calls be equal: chrono::duration_cast<chrono::seconds>(x) chrono::floor<chrono::seconds>(x) 回答1: As far as I can tell, same as the difference between static_cast and std

How to convert a fractional epoch timestamp (double) to an std::chrono::time_point?

穿精又带淫゛_ 提交于 2019-12-23 07:46:36
问题 I have a fractional epoch timestamp, represented as double , that I would like to convert to an appropriate std::chrono::time_point . The epoch is the usual UNIX epoch since 1/1/1970. I know that there exists std::chrono::system_clock::from_time_t , but a time_t does not have a fractional part. What would be the best way to do this with C++11 means? This question is related to unix timestamp to boost::posix_time::ptime, except that it's asking for the C++11 rather than Boost version of it.

convert seconds as double to std::chrono::duration?

吃可爱长大的小学妹 提交于 2019-12-23 06:47:17
问题 I'm using c++11 <chrono> and have a number of seconds represented as a double. I want to use c++11 to sleep for this duration, but I cannot fathom how to convert it to a std::chrono::duration object that std::this_thread::sleep_for requires. const double timeToSleep = GetTimeToSleep(); std::this_thread::sleep_for(std::chrono::seconds(timeToSleep)); // cannot convert from double to seconds I've locked at the <chrono> reference but I find it rather confusing. Thanks EDIT: The following gives

How to install a reoccurring timer function?

浪子不回头ぞ 提交于 2019-12-23 04:34:11
问题 Is there a simple way to install a regularly occurring timer function with C++/stdlib? I would like to get rid of the loop: using namespace std::chrono; // literal suffixes auto tNext = steady_clock::now(); while (<condition>) { std::this_thread::sleep_until(tNext); tNext = tNext + 100ms; ... That function will run in its own thread. 回答1: I'm guessing what you want is this int i = 10; auto pred = [i]() mutable {return i--;}; auto print = []{cout << "." << endl;}; timer t{500ms}; t.push({print

How to install a reoccurring timer function?

让人想犯罪 __ 提交于 2019-12-23 04:34:01
问题 Is there a simple way to install a regularly occurring timer function with C++/stdlib? I would like to get rid of the loop: using namespace std::chrono; // literal suffixes auto tNext = steady_clock::now(); while (<condition>) { std::this_thread::sleep_until(tNext); tNext = tNext + 100ms; ... That function will run in its own thread. 回答1: I'm guessing what you want is this int i = 10; auto pred = [i]() mutable {return i--;}; auto print = []{cout << "." << endl;}; timer t{500ms}; t.push({print

Std::chrono or boost::chrono support for CLOCK_MONOTONIC_COARSE

耗尽温柔 提交于 2019-12-22 18:04:08
问题 Running on Linux (uname says:) Linux 2.6.32-431.29.2.el6.x86_64 #1 SMP Sun Jul 27 15:55:46 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux My tests show that clock_gettime calls with a clock id of CLOCK_MONOTONIC_COARSE are an order of magnitude faster than calls that use a clock id CLOCK_MONOTONIC. Here's a sample output from a test run which called clock_gettime one million times in a tight loop and measured the lapsed time in milliseconds: CLOCK_MONOTONIC lapse 795 CLOCK_MONOTONIC_COARSE lapse 27

Std::chrono or boost::chrono support for CLOCK_MONOTONIC_COARSE

泄露秘密 提交于 2019-12-22 18:03:43
问题 Running on Linux (uname says:) Linux 2.6.32-431.29.2.el6.x86_64 #1 SMP Sun Jul 27 15:55:46 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux My tests show that clock_gettime calls with a clock id of CLOCK_MONOTONIC_COARSE are an order of magnitude faster than calls that use a clock id CLOCK_MONOTONIC. Here's a sample output from a test run which called clock_gettime one million times in a tight loop and measured the lapsed time in milliseconds: CLOCK_MONOTONIC lapse 795 CLOCK_MONOTONIC_COARSE lapse 27

How can I Populate a chrono::year With the Current Year?

↘锁芯ラ 提交于 2019-12-22 08:49:22
问题 So I understand from this question that the integer used in the construction of a chrono::year corresponds to the Anno Domini origin of 0. So my question is, what if I wanted to get the current chrono::year . Is there a function for that? I can obviously do: const auto time = std::time(nullptr); const auto current_date = *std::gmtime(&time); const chrono::year foo{ current_date.tm_year + 1900 }; But that seems like a pretty convoluted process. Is there anything better available to me? 回答1: