delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2002/10/17/08:31:50

To: eliz AT is DOT elta DOT co DOT il
Cc: djgpp-workers AT delorie DOT com
References: <Pine DOT SUN DOT 3 DOT 91 DOT 1021017073456 DOT 3848B-100000 AT is>
Message-Id: <2.7.9.2472D.H44KS3@pauzner.dnttm.ru>
From: "Leonid Pauzner" <uue AT pauzner DOT dnttm DOT ru>
Date: Thu, 17 Oct 2002 16:16:51 +0400 (MSD)
X-Mailer: dMail [Demos Mail for DOS v2.7.9]
Subject: Re: libc' ctime.c optimizations
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com

>> I mean a caching within an hour directly inside mktime(),

> As for `gettimeofday', what kind of applications calls it so massively as
> to justify caching?  Isn't it better to move this caching into
> `gettimeofday' itself?

Agree. Let we cache in gettimeofday().

gettimeofday() heavily used by select().
And many applications written by unix developers -
perhaps gettimeofday more portable then usec timers.



diff -u old/gettimeo.c ./gettimeo.c
--- old/gettimeo.c      Sat Mar 11 05:42:42 1995
+++ ./gettimeo.c        Thu Oct 17 15:18:18 2002
@@ -2,6 +2,11 @@
 #include <libc/stubs.h>
 #include <time.h>
 #include <dpmi.h>
+#include <libc/environ.h>
+
+static int        last_env_changed = 0;
+static struct tm  prev;
+static int        prev_sec;

 int gettimeofday(struct timeval *tv, struct timezone *tz)
 {
@@ -32,7 +37,24 @@
   tmblk.tm_zone = 0;
   tmblk.tm_isdst = -1;

-  tv->tv_sec = mktime(&tmblk);
+  /* 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;
+  }

   if(tz)
   {


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019