|
|
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
|
|
0
|
|
|
|
Reply
|
a.k.vora (41)
|
9/18/2008 8:08:44 AM |
|
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
|
|
0
|
|
|
|
Reply
|
a.k.vora (41)
|
9/18/2008 8:09:33 AM
|
|
Ashit Vora wrote:
> I tried following code (for the meanwhile 'm tring to get time in
> mili
> secs)
> long int secs;
> secs=time(NULL);
So why call a function that returns the time in seconds?
> 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.
Total nonsense.
You obviously didn't compile what you posted.
Post what you compiled.
--
Ian Collins.
|
|
0
|
|
|
|
Reply
|
ian-news (9880)
|
9/18/2008 8:17:48 AM
|
|
On Thu, 18 Sep 2008 01:09:33 -0700, Ashit Vora wrote:
> long int secs;
> secs=time(NULL);
> this gives me ab error in the line SECS=TIME (NULL)
That line isn't in the code above.
secs=time(NULL);
is not the same as
SECS=TIME (NULL)
|
|
0
|
|
|
|
Reply
|
tom.viza3 (154)
|
9/18/2008 1:23:27 PM
|
|
In <07fd2151-588c-4290-8de6-c0af8a16590d@p31g2000prf.googlegroups.com> Ashit Vora <a.k.vora@gmail.com> writes:
> 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
Did you include the time.h header file?
--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
|
|
0
|
|
|
|
Reply
|
gordon16 (619)
|
9/18/2008 1:59:59 PM
|
|
Ashit Vora <a.k.vora@gmail.com> writes:
> I want to find the current time stamp in micro sec precision.
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.
|
|
0
|
|
|
|
Reply
|
ben.usenet (6515)
|
9/18/2008 3:31:33 PM
|
|
In article
<07fd2151-588c-4290-8de6-c0af8a16590d@p31g2000prf.googlegroups.com>,
Ashit Vora <a.k.vora@gmail.com> wrote:
> 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)
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.
> 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?
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.
|
|
0
|
|
|
|
Reply
|
wayne.morris (948)
|
9/18/2008 5:36:37 PM
|
|
On Thu, 18 Sep 2008 01:08:44 -0700 (PDT), Ashit Vora <a.k.vora@gmail.com> wrote:
> Hi,
> I want to find the current time stamp in micro sec precision.
You can use clock_gettime() and clock_getres() for this part.
> 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.
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.
> So my requirement is printing the current timestamps.
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?
|
|
0
|
|
|
|
Reply
|
keramida (459)
|
9/19/2008 5:07:46 AM
|
|
|
7 Replies
40 Views
(page loaded in 0.16 seconds)
|
|
|
|
|
|
|
|
|