• C

alternative to mktime and localtime

I'm writing an application where I have to call localtime
and mktime millions of times.  Unfortunately, they
decrease the overall perfomance of the software considerably (2-5 times slower). Does anybody know of any alternative
alogrithms to replace mktime and localtime that are optimized for speed?
Who is Participating?
Perhaps you are using localtime and mktime to get "the value of time in seconds  since  EPOCH"
In this case you should take benefit to use the System Call:
 time :
     time - get time

     #include <sys/types.h>
     #include <time.h>

     time_t time(time_t *tloc);


     time() returns the value of time in seconds  since  00:00:00
     UTC, January 1, 1970.

What are you trying to do? Why do you have to call these functions so often?
For what they do mktime and localtime are probably higly tuned already.

stomljenAuthor Commented:
A good answer by it doesn't really answer my question, but
perhaps I haven't been explicit enough.  Anyway, I think
I figured out the only reasonable approach is to try
to reduce my calls to mktime and localtime.
You should either reject or accept this answer otherwise the question will hang around for ages.

My suggestion would be to use the 'time' functions to keep a long-term time base, and use clock() to handle short-term increments to it.  On most systems clock() is very fast.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.