Solved

alternative to mktime and localtime

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now