From p.dalgaard at biostat.ku.dk  Thu May  5 16:28:49 2005
From: p.dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: Thu May  5 16:29:00 2005
Subject: [Rd] Varying as.Date performance
In-Reply-To: <17018.7818.716318.388693@gargle.gargle.HOWL>
References: <17017.17895.337156.535491@gargle.gargle.HOWL>
	<Pine.LNX.4.61.0505050717100.20206@gannet.stats>
	<17018.7818.716318.388693@gargle.gargle.HOWL>
Message-ID: <x2vf5xlpb2.fsf@turmalin.kubism.ku.dk>

Jeff Enos <jeff@kanecap.com> writes:

> Thanks for these suggestions.  C-level profiling yields the following:
> 
>   %   cumulative   self              self     total
>  time   seconds   seconds    calls   s/call   s/call  name
>  36.01      5.34     5.34   100000     0.00     0.00  get_locale_strings
>   4.32      5.98     0.64   100000     0.00     0.00  mktime00
>   3.98      6.57     0.59   277462     0.00     0.00  Rf_eval
>   3.71      7.12     0.55   472935     0.00     0.00  Rf_findVarInFrame3
>   3.64      7.66     0.54   100000     0.00     0.00  strptime_internal
>   3.51      8.18     0.52        1     0.52     7.51  do_strptime
> 
> It looks like strftime is called from get_locale_strings, which might
> be the culprit.  Any suggestions on where I might go from here?

You might try modifying get_locale_strings (and its wide counterpart)
with a check for an unchanged locale. E.g.

static char *last_LC_TIME=NULL;

....

  tmp = setlocale(LC_TIME, NULL)
  if (strcmp(tmp, last_LC_TIME)) return;
  
  last_LC_TIME = tmp; 

.... set the strings ....

if the call to setlocale is considerably faster than 40 calls to
strftime(), you might have a winner.



-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907


[Rd] Varying as.Date performance
Peter Dalgaard