Solved

alternative to mktime and localtime

Posted on 1997-04-16
4
1,763 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
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.

808 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