To: djgpp-workers AT delorie DOT com References: <10210150631 DOT AA20605 AT clio DOT rice DOT edu> Message-Id: <2.7.9.1KWON.H418CY@pauzner.dnttm.ru> From: "Leonid Pauzner" Date: Tue, 15 Oct 2002 20:55:46 +0400 (MSD) X-Mailer: dMail [Demos Mail for DOS v2.7.9] Subject: libc' ctime.c optimizations MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp-workers AT delorie DOT com 15-Oct-2002 01:28 Charles Sandmann wrote: > If we cache getenv() properly in the tzset(), we'll only call it once. > Here's my proposed patch for ctime.c: This will not help too much since other time functions patalogically ineffective also. Look onto mktime - time1 - time2 - localsub - timesub - days_to_years ... functions chain (the attached profile gives a nice picture): 3800 mktime() calls requires 130000 calls of days_to_years() which costs nearly the same as all getenv calls before your patch (while days_to_years could easily be cached from the previous call). And so on. Also, since time functions usually called in present it may be reasonable to calculate seconds since the release day (or some date in 2002) and then add a constant distance from 1970, transparently to the user. > *** ctime.bak Sun Jun 9 13:20:22 2002 > --- ctime.c Tue Oct 15 01:24:06 2002 > *************** tzset(void) > *** 920,926 **** > /* If environ didn't changed since last time, don't waste time > looking at $TZ. */ > ! if (lcl_is_set > 0 && __environ_changed == last_env_changed) > return; > /* If environ did change, but $TZ wasn't changed since last time we > --- 920,926 ---- > /* If environ didn't changed since last time, don't waste time > looking at $TZ. */ > ! if (lcl_is_set != 0 && __environ_changed == last_env_changed) > return; > /* If environ did change, but $TZ wasn't changed since last time we Flat profile: Each sample counts as 0.0555556 seconds. % cumulative self self total time seconds seconds calls ms/call ms/call name 4.38 12.44 1.00 130356 0.01 0.01 days_to_years 2.68 16.94 0.61 130356 0.00 0.01 timesub 0.49 20.39 0.11 130356 0.00 0.00 __tzset 0.24 21.67 0.06 126522 0.00 0.00 tmcomp 0.00 22.83 0.00 130356 0.00 0.01 localsub 0.00 22.83 0.00 3834 0.00 0.46 mktime 0.00 22.83 0.00 3834 0.00 0.46 time1 0.00 22.83 0.00 3834 0.00 0.00 tmnormalize ----------------------------------------------- [9] 8.5 0.06 1.78 3830 __gettimeofday [9] 0.00 1.78 3830/3834 mktime [11] ----------------------------------------------- 0.06 1.73 3834/3834 time1 [12] [10] 8.3 0.06 1.73 3834 time2 [10] 0.00 1.67 126522/130356 localsub [14] 0.06 0.00 126522/126522 tmcomp [76] 0.00 0.00 3834/3834 tmnormalize [318] ----------------------------------------------- 0.00 1.78 3830/3834 __gettimeofday [9] [11] 8.3 0.00 1.78 3834 mktime [11] 0.00 1.78 3834/3834 time1 [12] ----------------------------------------------- 0.00 1.78 3834/3834 mktime [11] [12] 8.3 0.00 1.78 3834 time1 [12] 0.06 1.73 3834/3834 time2 [10] ----------------------------------------------- 0.00 0.05 3834/130356 label [61] 0.00 1.67 126522/130356 time2 [10] [14] 8.0 0.00 1.72 130356 localsub [14] 0.61 1.00 130356/130356 timesub [17] 0.11 0.00 130356/130356 __tzset [53] ----------------------------------------------- 0.61 1.00 130356/130356 localsub [14] [17] 7.5 0.61 1.00 130356 timesub [17] 1.00 0.00 130356/130356 days_to_years [20] ----------------------------------------------- 0.11 0.00 130356/130356 localsub [14] [53] 0.5 0.11 0.00 130356 __tzset [53] 0.00 0.00 1/71 getenv [194] 0.00 0.00 1/2 tzload [290] 0.00 0.00 1/1 gmtload [293] 0.00 0.00 1/2 tzparse [427] 0.00 0.00 1/1 settzname [494] -----------------------------------------------