7 ms·
Libstdc++ Gets C++20 Chrono
- synergy20 4y agosomehow I thought we had this already as I used chrono in my code, what am I missing? fmt however is not there to use yet.
- jeffbee 4y agoWe've had things like time_point for a while but this is civil time stuff: calendar and time zone.
- mort96 4y agostd::chrono was introduced in C++11, but it got a bunch of enhancements in C++20.
- beached_whale 4y agoC++20 adds the timezone/caldendaring/formatting from Howard Hinnat’s Date Library https://github.com/howardhinnant/date https://github.com/howardhinnant/date . So calendrical calculations and time zone support.
- xeeeeeeeeeeenu 4y ago> fmt however is not there to use yet. GCC 13 will have <format>: https://gcc.gnu.org/pipermail/libstdc++/2022-November/054991.html https://gcc.gnu.org/pipermail/libstdc++/2022-November/054991...
- glitchc 4y agoBefore <chrono>, any high performance timing operation (ms and below) was a nightmare. Any solution one could conceive of was highly dependent on local system calls which in turn would vary based on OS scheduler and CPU idiosyncrasies. <chrono> abstracts all of that away and replaces it with an easy to use API that is cross-platform. It was a god-send for a project many moons ago. Required me to upgrafe to C++14 but totally worth it. Kudos to the <chrono> team for resolving such a painful issue!
- rurban 4y agoIt still is totally unreliable, and avoids documented best practices. https://www.intel.com/content/dam/www/public/us/en/documents/white-papers/ia-32-ia-64-benchmark-code-execution-paper.pdf https://www.intel.com/content/dam/www/public/us/en/documents... 3.2.1 The Improved Benchmarking Method
- fooblaster 4y agoIs there a reasonable way to do this without disabling preemption? All of these examples require the code to be in the kernel or for the kernel to be modified, which isn't really useful in all the places you need to benchmark.
- rurban 4y agoNo, you need a proper API for benchmarking. chrono only gives you one, for a single timestamp. Benchmarking needs a separate timer_start and timer_end function. One with cpuid,rdtsc and one with rdtscp,cpuid.
- fooblaster 4y agoIts very easy to get two timestamps at the start and end of the routine and subtract the difference with Chrono. No cpu pinning or preemption control is necessary.
- flohofwoe 4y agoI remember that at least early versions of MSVC std::chrono only offered a 'high resolution' clock with 1 ms granularity. Not sure how the current situation is, I've since gone back to QueryPerformanceCounter, mach_absolute_time(), etc... it's not much of an effort to wrap those platform-specific calls into a very small cross-platform API, and at least those functions work as advertised.