delorie.com/archives/browse.cgi | search |
Date: | Thu, 17 Oct 2002 10:01:10 -0400 |
Message-Id: | <200210171401.g9HE1AR24630@envy.delorie.com> |
X-Authentication-Warning: | envy.delorie.com: dj set sender to dj AT delorie DOT com using -f |
From: | DJ Delorie <dj AT delorie DOT com> |
To: | djgpp-workers AT delorie DOT com |
In-reply-to: | <2.7.9.2472D.H44KS3@pauzner.dnttm.ru> (uue@pauzner.dnttm.ru) |
Subject: | Re: libc' ctime.c optimizations |
References: | <Pine DOT SUN DOT 3 DOT 91 DOT 1021017073456 DOT 3848B-100000 AT is> <2 DOT 7 DOT 9 DOT 2472D DOT H44KS3 AT pauzner DOT dnttm DOT ru> |
Reply-To: | djgpp-workers AT delorie DOT com |
Errors-To: | nobody AT delorie DOT com |
X-Mailing-List: | djgpp-workers AT delorie DOT com |
X-Unsubscribes-To: | listserv AT delorie DOT com |
If you assume gettimeofday() will be called multiple times per hour, it's faster to subtract off the minutes and seconds when storing prev_sec, so that you don't have to keep doing it over and over. Thus, you cache the tv_sec for the beginning of the hour, not for the last time used. > + /* cache expensive mktime() calls, until next hour */ > + if (last_env_changed == __environ_changed && > + prev.tm_hour == tmblk.tm_hour && > + prev.tm_mday == tmblk.tm_mday && > + prev.tm_mon == tmblk.tm_mon && > + prev.tm_year == tmblk.tm_year) > + { > + tv->tv_sec = prev_sec + (tmblk.tm_sec - prev.tm_sec) > + + (tmblk.tm_min - tmblk.tm_min)*60; > + } > + else > + { > + tv->tv_sec = mktime(&tmblk); > + > + prev_sec = tv->tv_sec; > + prev = tmblk; > + last_env_changed = __environ_changed; > + }
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |