Connecting Tech Pros Worldwide Forums | Help | Site Map

How to maintain time in a C program

Haneef
Guest
 
Posts: n/a
#1: Oct 5 '07
Hi All

The problem is that I need to keep track of time in my program.

Getting time using system calls every time I need is definitely very
expensive.

So one solution could be to spawn a thread and keep incrementing the
time. But I dont want another thread just to maintain the time.

Please let me know if you have any other solutions. Any Links also
would be helpful.

Thanks in advance,
Haneef


Haneef
Guest
 
Posts: n/a
#2: Oct 5 '07

re: How to maintain time in a C program


Someone please let me know "How can I keep track or maintain time in
my program" ?

Martien verbruggen
Guest
 
Posts: n/a
#3: Oct 5 '07

re: How to maintain time in a C program


On Fri, 05 Oct 2007 09:42:54 -0000,
Haneef <haneef0786@gmail.comwrote:
Quote:
Someone please let me know "How can I keep track or maintain time in
my program" ?
You haven't exactly explained what was wrong with the answers that you
already got.

In what way was that not what you were looking for? Could you maybe be a
bit more clear? Are you maybe looking for time, localtime(), mktime()
and strftime()?

Without you being more specific and clear about exactly what it is
you're trying to do, and what exactly you're doing when you talk about
"system calls". I doubt anyone can give you more help.

Martien
--
|
Martien Verbruggen |
| What's another word for Thesaurus?
|
Mark McIntyre
Guest
 
Posts: n/a
#4: Oct 5 '07

re: How to maintain time in a C program


On Fri, 05 Oct 2007 09:14:01 -0000, in comp.lang.c , Haneef
<haneef0786@gmail.comwrote:
Quote:
>I am talking about the calendar time. Its just that time is to be used
>so many times
Why? This sounds like a design flaw.
Quote:
>(not to mention at different points of time) that system
>call would be expensive.
Yes, but have you actually /measured/ this, to prove it is a real
problem? Bear in mind that many many real applications out in the real
world use timestamps, and its generally isn't an issue.
Quote:
>So many calls when only one can suffice is
>definitely not recommended.
It might *feel* like a bad idea, but you don't seem to have any
evidence that it really is. Remember the Three Laws of Optimisation.
Quote:
>Hey, I am just a newbie.
Thats ok.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Mark McIntyre
Guest
 
Posts: n/a
#5: Oct 5 '07

re: How to maintain time in a C program


On Fri, 05 Oct 2007 09:42:54 -0000, in comp.lang.c , Haneef
<haneef0786@gmail.comwrote:
Quote:
>Someone please let me know "How can I keep track or maintain time in
>my program" ?
You won't get more help by asking the same quesiton twice and ignoring
all the answers you got the first time.

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Thad Smith
Guest
 
Posts: n/a
#6: Oct 6 '07

re: How to maintain time in a C program


Haneef wrote:
Quote:
The problem is that I need to keep track of time in my program.
>
Getting time using system calls every time I need is definitely very
expensive.
The acceptability of the execution time depends on your timing
constraints. How often does your application need to check the time?
How did you arrive at that interval? How long does it take for a system
call on your target system to return the time?

Most desktop applications should work fine with standard system time
routines. Real-time applications can have tighter constraints. I have
written applications that directly read a timer register for short time
interval measurements, but they required execution time of a few
microseconds on slow 8-bit processors.

Try the simplest approach first, using standard functions. If you think
that is a significant bottleneck measure the cost, determine the impact,
and evaluate the alternatives. You may be thinking of obtaining the
system time more often than you need.

--
Thad
Chris Hills
Guest
 
Posts: n/a
#7: Oct 6 '07

re: How to maintain time in a C program


In article <1191564388.848115.146690@50g2000hsm.googlegroups. com>,
Haneef <haneef0786@gmail.comwrites
Quote:
>Hi All
>
>The problem is that I need to keep track of time in my program.
>
>Getting time using system calls every time I need is definitely very
>expensive.
>
>So one solution could be to spawn a thread and keep incrementing the
>time. But I dont want another thread just to maintain the time.
>
>Please let me know if you have any other solutions. Any Links also
>would be helpful.
It largely depends on your target environment.

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ chris@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/



Mike Wahler
Guest
 
Posts: n/a
#8: Oct 7 '07

re: How to maintain time in a C program



"Haneef" <haneef0786@gmail.comwrote in message
news:1191564388.848115.146690@50g2000hsm.googlegro ups.com...
Quote:
Hi All
>
The problem is that I need to keep track of time in my program.
>
Getting time using system calls every time I need is definitely very
expensive.
How do you know? Did you measure? If not, then you do NOT know.
Quote:
>
So one solution could be to spawn a thread and keep incrementing the
time.
Perhaps. But then you also introduce additional complexity,
perhaps unnecessarily.
Quote:
But I dont want another thread just to maintain the time.
I would not either.
Quote:
>
Please let me know if you have any other solutions.
I would first use the simplest solution (i.e. the standard library),
and only if profiling proved it unacceptable, would I seek another.

If I did prove there's a performance issue, I'd then look to the
host operating system facilites, as they'd be most likely be
optimized for the target environment.

-Mike


Closed Thread