'Cheapest' way of getting time stamp in Linux (c++) -


i wondering cheapest way of getting timestamp in linux (in c++).
assume it's accuracy trade-of believe there more 1 possibility.
need have milliseconds not microseconds, std::localtime isn't option , gettimeofday costly. (due microseconds accuracy).

1: fprintf(stdout, "%u\n", (unsigned)time(null));

2: struct timeval tv; gettimeofday(&tv,null); tv.tv_sec // seconds tv.tv_usec // microseconds

3: std::time_t result = std::time(nullptr); std::cout << std::asctime(std::localtime(&result)) << result << " seconds since epoch\n";

4:

using namespace std::chrono; milliseconds ms = duration_cast< milliseconds >(     high_resolution_clock::now().time_since_epoch() );` 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -