getting current timestamp
Hi,
I want to find the current time stamp in micro sec precision.
The requirement is,
my function is executed in an infinite loop.
I measure a value and check if the value computed is what i expected
9forget all this stuff).
I want to print the time stamp every time that event occurs.
So my requirement is printing the current timestamps.
so I can calculate the average time (in micro secs) after which such
an event occur...
I hope I made my requirement clear.
Can anybody pls help me with this problem.
I searched many discussion but couldn't find satisfactory answer.
thanks in advance
Re: getting current timestamp
I tried following code (for the meanwhile 'm tring to get time in
mili
secs)
long int secs;
secs=time(NULL);
this gives me ab error in the line SECS=TIME (NULL)
error: expected constructor, destructor, or type conversion before
'=' token
but if I directly print the value time(null) it works fine.
so there's some prob with type casting, I guess.
what can be the solution for this?
Thanks in advance
Re: getting current timestamp
A**** Vora wrote:[color=blue]
> I tried following code (for the meanwhile 'm tring to get time in
> mili
> secs)
> long int secs;
> secs=time(NULL);[/color]
So why call a function that returns the time in seconds?
[color=blue]
> this gives me ab error in the line SECS=TIME (NULL)
> error: expected constructor, destructor, or type conversion before
> '=' token
> but if I directly print the value time(null) it works fine.
> so there's some prob with type casting, I guess.[/color]
Total nonsense.
You obviously didn't compile what you posted.
Post what you compiled.
--
Ian Collins.
Re: getting current timestamp
On Thu, 18 Sep 2008 01:09:33 -0700, A**** Vora wrote:
[color=blue]
> long int secs;
> secs=time(NULL);[/color]
[color=blue]
> this gives me ab error in the line SECS=TIME (NULL)[/color]
That line isn't in the code above.
secs=time(NULL);
is not the same as
SECS=TIME (NULL)
Re: getting current timestamp
In <07fd2151-588c-4290-8de6-c0af8a16590d@p31g2000prf.googlegroups.com> A**** Vora <a.k.vora@gmail.com> writes:
[color=blue]
> I tried following code (for the meanwhile 'm tring to get time in
> mili
> secs)
> long int secs;
> secs=time(NULL);
> this gives me ab error in the line SECS=TIME (NULL)
> error: expected constructor, destructor, or type conversion before
> '=' token[/color]
Did you include the time.h header file?
--
John Gordon A is for Amy, who fell down the stairs
[email]gordon@panix.com[/email] B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
Re: getting current timestamp
A**** Vora <a.k.vora@gmail.com> writes:
[color=blue]
> I want to find the current time stamp in micro sec precision.[/color]
The most portable solution is probably the POSIX function
clock_getres
clock_gettime
The first will tell you resolution and the second one the time. You
get (on most systems) a number of slightly different clocks like
CLOCK_REALTIME, CLOCK_MONOTONIC and possibly CLOCK_PROCESS_CPUTIME_ID.
See "man clock_gettime" to see of you have these available on your
system.
--
Ben.
Re: getting current timestamp
In article
<07fd2151-588c-4290-8de6-c0af8a16590d@p31g2000prf.googlegroups.com>,
A**** Vora <a.k.vora@gmail.com> wrote:
[color=blue]
> I tried following code (for the meanwhile 'm tring to get time in
> mili
> secs)
> long int secs;
> secs=time(NULL);
> this gives me ab error in the line SECS=TIME (NULL)[/color]
No it didn't, because that line doesn't exist in the code you listed.
C/C++ is case-sensitive. SECS is not the same as secs and TIME is not
the same as time.
[color=blue]
> error: expected constructor, destructor, or type conversion before
> '=' token
> but if I directly print the value time(null) it works fine.
> so there's some prob with type casting, I guess.
> what can be the solution for this?[/color]
secs is an int. time does not return an int. Read the man page.
But you said you wanted millisecond or microsecond accuracy, so why are
you using a function that will only give you seconds? Use gettimeofday
or clock_gettime.
Re: getting current timestamp
On Thu, 18 Sep 2008 01:08:44 -0700 (PDT), A**** Vora <a.k.vora@gmail.com> wrote:[color=blue]
> Hi,
> I want to find the current time stamp in micro sec precision.[/color]
You can use clock_gettime() and clock_getres() for this part.
[color=blue]
> The requirement is, my function is executed in an infinite loop. I
> measure a value and check if the value computed is what i expected
> (forget all this stuff). I want to print the time stamp every time
> that event occurs.[/color]
Don't print the timestamps, but aggregate them while the program runs.
Even if each function call takes a very small amount of time to
complete, printing is very likely to:
* Take much longer to reach stdout or stderr.
* Be buffered.
* Take an unpredictabe amount of time.
[color=blue]
> So my requirement is printing the current timestamps.[/color]
This sounds like what you _think_ the requirement is.
The real requirement seems to be ``to profile a specific function''.
There are excellent profiling tools out there. Maybe one of them is
better than printing timestamps?