0

My doubt is something that I believe should be simple for anyone who already develops.

But unfortunately I didn't find the answer on the Stackoverflow platform or even on Google!

Believe me, I found the opposite but nothing about my problem.

My question: There are several ways to get the time in Windows and Linux operating systems, among them some use different techniques, such as CPU or Wall time etc.

But which of the existing techniques for both operating systems have the lowest call cost? That is, can it be called multiple times with little overhead?

Yes, despite finding several answers referring to different precisions and situations, I didn't find any that fit my use case.

Imagine a multi-threaded application that for each action, whether called an endpoint or anything else, needs to register the last hour of execution in a static global variable in integer or long format?

For this reason I want to know which system call, in both (Windows and Linux) have the least overhead.

Observation: Even if it is a hypothetical situation, and does not refer to any real application, please do not comment something like "Don't worry about it, just use whatever", because however true this is, my doubt as explained above it's about a hypothetical example, so if there wasn't the curiosity to know the answer, I wouldn't have posted the question !

I'm trying to satisfy my curiosity and waiting for a scientific answer to the question.

Important Note: The calling method must be in C or C++ language, that is, in javascript you can use new Date().getTime(), among others depending on the language.

But, my question is limited to C/C++ using pure native APIs, ie std::chrono::system_clock::now() doesnt count !

Gabriel
  • 19
  • 1
  • 3
  • What do you mean by "last hour of execution"? The hour component of the wall time, when it was last executed? – Solomon Ucko Mar 20 '23 at 01:52
  • @SolomonUcko I'm referring to storing the current time (regardless of whether it's cpu time [per cycles/etc] or current system time) that has the least call overhead. – Gabriel Mar 20 '23 at 01:54
  • 1
    Check these [answer1](https://stackoverflow.com/a/20586756/14270816) [answer2](https://stackoverflow.com/a/20586708/14270816) [article](https://pythonspeed.com/articles/blocking-cpu-or-io/) But TLDR; CPU time method usually has lower overhead than Wall time since it measures the amount of time the CPU has spent executing a program, whilst Wall time method measures the amount of time that has passed in real time. – Ietu Mar 20 '23 at 01:55
  • 1
    Thanks, the rdtsc function helped ! – Gabriel Mar 20 '23 at 02:01

0 Answers0