Solved

alternative to mktime and localtime

Posted on 1997-04-16
4
1,789 Views
Last Modified: 2010-05-19
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?
0
Comment
Question by:stomljen
4 Comments
 
LVL 3

Expert Comment

by:LucHoltkamp
ID: 1249927
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.

0
 
LVL 1

Accepted Solution

by:
OM earned 100 total points
ID: 1249928
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 :
NAME
     time - get time

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

     time_t time(time_t *tloc);

MT-LEVEL
     Async-Signal-Safe

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


0
 

Author Comment

by:stomljen
ID: 1249929
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.
0
 
LVL 1

Expert Comment

by:prc
ID: 1249930
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.

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question