What is the best alternative gettimeofday () library in C ++?

Is there an alternative to ORT using gettimeofday () in C ++ for Linux? For example, I like to write code similar to this:

DateTime now = new DateTime;
DateTime duration = new DateTime(2300, DateTime.MILLISECONDS)
DateTime deadline = now + duration;

while(now < deadline){
    DoSomething();
    delete now;
    now = new DateTime()
}

The goal is the Linux embedded system, and there are no Boost libraries, but maybe there is something that is easy to port (for example, something is implemented with header files).

+3
source share
4 answers

Thus, increasing the load was not an option for my purpose. Instead, I had to go with gettimeofday (). However, there are some good macros for working with timeval structures insys/time.h

#include <sys/time.h>

void timeradd(struct timeval *a, struct timeval *b,
          struct timeval *res);

void timersub(struct timeval *a, struct timeval *b,
          struct timeval *res);

void timerclear(struct timeval *tvp);

void timerisset(struct timeval *tvp);

void timercmp(struct timeval *a, struct timeval *b, CMP);

, , man . . : http://linux.die.net/man/3/timercmp

+2

- , ++.

, Boost.Date_Time. Boost , ++.

+6

, ctime

#include <ctime>

time
difftime
mktime

. cplusplus.com

0
/usr/include/linux/time.h 

: -

struct timeval {
    time_t      tv_sec;     /* seconds */
    suseconds_t tv_usec;    /* microseconds */
};

Linux, , ...

0

Source: https://habr.com/ru/post/1731335/


All Articles