Hacker News new | past | comments | ask | show | jobs | submit login
Libstdc++ Gets C++20 Chrono (isocpp.org)
45 points by alonp99 on Dec 24, 2022 | hide | past | favorite | 11 comments



Before <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!


It still is totally unreliable, and avoids documented best practices.

https://www.intel.com/content/dam/www/public/us/en/documents...

3.2.1 The Improved Benchmarking Method


Is 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.


No, 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.


Its 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.


I 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.


somehow 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.


C++20 adds the timezone/caldendaring/formatting from Howard Hinnat’s Date Library https://github.com/howardhinnant/date .

So calendrical calculations and time zone support.


> fmt however is not there to use yet.

GCC 13 will have <format>: https://gcc.gnu.org/pipermail/libstdc++/2022-November/054991...


We've had things like time_point for a while but this is civil time stuff: calendar and time zone.


std::chrono was introduced in C++11, but it got a bunch of enhancements in C++20.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: