Re: Subtracting Microseconds from Timestamp




dev/null wrote:

dn> Hello, I'm a UNIX newbie. I'm trying to get the time elapse between
dn> some queries. I have a timestamp, and then another time in
dn> miliseconds. I'm having trouble getting the difference. For example,
dn> initial time is 1251935975

This timestamp form (I guess it's unixtime in seconds) doesn't contain
parts of seconds at all, so isn't suitable to measure intervals with
required precision.

You should use gettimeofday() or clock_gettime() which also give parts
of seconds, accordingly in microseconds or nanoseconds.

dn> but the microseconds I'm given after the
dn> query is 80192300.

If this is really microseconds count, it means ~80 seconds, but I
don't know call which gives this.

If you need to get interval between two queries, use the same request
type and calculate difference. In userland, you can use real values
for this:

#include <sys/time.h>
double etime(void)
{
struct timeval tv;
gettimeofday(&tv, NULL); // it's _quite_ unlikely to fail
return tv.tv_sec + tv.tv_usec / 1000000.0;
}

Then, you can simply do

t0 = etime();
do a query;
t1 = etime();
printf("Elapsed time: %g\n", t1 - t0);


--netch--
.



Relevant Pages

  • Re: Subtracting Microseconds from Timestamp
    ... | some queries. ... I have a timestamp, ... If the numeric values are number of seconds, and number of microseconds, ... long long usec; ...
    (comp.unix.programmer)
  • Re: anybody use MySQL?
    ... You, however, do have to download and distribute the ODBC driver to every ... time and timestamp consistently. ... Also, if queries, especially one written for recordsources or rowsources, ... row if it does not have a primary key. ...
    (microsoft.public.access.gettingstarted)
  • Re: Extended-Precision Division
    ... specifically I am taking a timestamp from rdtsc and converting it into microseconds. ... First I have to multiply by 1,000,000 to get a temporary 96-bit product, and then I can divide by the CPU frequency. ... It does not hurt to have too much precision, so I am using microseconds for my counter. ...
    (comp.lang.asm.x86)
  • RE: memory mapped packet capturing - bpf replacement ?
    ... > There's no reason why the time has to be in microseconds or ... > even that it must be adjusted to realtime. ... I pointed out the timestamp issue only because it will penalize ...
    (freebsd-hackers)
  • RE: anybody use MySQL?
    ... I have developed and implemented a project using MySQL as back-end to Access ... time and timestamp consistently. ... Also, if queries, especially one written for recordsources or rowsources, ... row if it does not have a primary key. ...
    (microsoft.public.access.gettingstarted)