I want to subtract two gettimeofday instances, and present the answer in milliseconds.
The idea is:
static struct timeval tv;
gettimeofday(&tv, NULL);
static struct timeval tv2;
gettimeofday(&tv2, NULL);
static struct timeval tv3=tv2-tv;
and then convert 'tv3' into milliseconds resolution.
You can use the timersub() function provided by glibc, then convert the result to milliseconds (watch out for overflows when doing this, though!).
Here's how to do it manually (since timersub isn't a standard function offered elsewhere)
(and you have to watch for overflow, which makes it even worse)
The current version of C++ offers a better option though: