Solved

alternative to mktime and localtime

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Picking random number 8 175
Why this code doesn't work? 8 97
Problem in finding output of a program 11 101
Why isn't object file created? 6 42
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 tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and reading files 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.

895 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

13 Experts available now in Live!

Get 1:1 Help Now