75% speedup for zdump on 64-bit Solaris sparc

Arthur David Olson olsona at lecserver.nci.nih.gov
Tue Mar 7 16:00:22 UTC 2006


The simplest way to avoid problems with the thread safeness comment is to
delete it. It also pays, of course, to get the code right. So...let's take
a look at this possible change:

===============================================================================
------- localtime.c -------
*** /tmp/geta21149	Tue Mar  7 10:52:03 2006
--- /tmp/getb21149	Tue Mar  7 10:52:03 2006
***************
*** 5,11 ****
  
  #ifndef lint
  #ifndef NOID
! static char	elsieid[] = "@(#)localtime.c	8.1";
  #endif /* !defined NOID */
  #endif /* !defined lint */
  
--- 5,11 ----
  
  #ifndef lint
  #ifndef NOID
! static char	elsieid[] = "@(#)localtime.c	8.3";
  #endif /* !defined NOID */
  #endif /* !defined lint */
  
***************
*** 1263,1271 ****
  				break;
  			}
  	} else {
! 		for (i = 1; i < sp->timecnt; ++i)
  			if (t < sp->ats[i])
  				break;
  		i = (int) sp->types[i - 1];
  	}
  	ttisp = &sp->ttis[i];
--- 1263,1281 ----
  				break;
  			}
  	} else {
! 		static int	guess;
! 
! 		i = guess;
! 		if (i < 1 || i >= sp->timecnt || t < sp->ats[i])
! 			i = 1;
! 		for ( ; i < sp->timecnt; ++i)
  			if (t < sp->ats[i])
  				break;
+ 		/*
+ 		** Heuristic alert: "guess = i - 1" caters to programs such as
+ 		** zdump that do lots of calls straddling a transition time.
+ 		*/
+ 		guess = i - 1;
  		i = (int) sp->types[i - 1];
  	}
  	ttisp = &sp->ttis[i];
===============================================================================

I used the script below for metering purposes here on the mother ship (a
500 MHz Sun Blade 100 running Solaris 8)...

	(
	sccs get -r8.1 localtime.c 
	make clean 
	make install TOPDIR=$PWD/tmp 2>/dev/null
	make clean 
	make zdump TOPDIR=$PWD/tmp CFLAGS="-D_TIME_T \"-Dtime_t=long long\"" 
	time ./zdump -v US/Pacific > /dev/null
	sccs get -r8.3 localtime.c 
	make clean 
	make zdump TOPDIR=$PWD/tmp CFLAGS="-D_TIME_T \"-Dtime_t=long long\"" 
	time ./zdump -v US/Pacific > /dev/null
	rm -f localtime.c
	cp eggert.c localtime.c
	make clean
	make zdump TOPDIR=$PWD/tmp CFLAGS="-D_TIME_T \"-Dtime_t=long long\"" 
	time ./zdump -v US/Pacific > /dev/null
	rm -f localtime.c
	) > /dev/null

...and got these results...


	real       38.5
	user       38.2
	sys         0.0

	real       19.7
	user       19.6
	sys         0.0

	real       20.7
	user       20.2
	sys         0.0

...for a virtual tie between the cache and search approaches.

				--ado



More information about the tz mailing list