This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PING^3] RFC [PATCH] BZ#1077902: New API gettimezone


On Wed, May 28, 2014 at 07:34:40AM -0700, Paul Eggert wrote:
> >No its same api. You just define timezone_t as char * so you do not have
> >to implement anything difficult.
> 
> But you'd still to make copies of the strings that the char *
> pointers point at, no?
> 
> Also, this sounds reallllly slow -- perhaps a reasonable
> proof-of-API-concept, but not reasonable as an actual change one
> would want to make to glibc.
> 
It is not that slow as a multithread application must do locking
somewhere to get predicable results and localtime now is bit slow.

I measured difference of uncontended performance, main bottleneck was
setenv so I added equality check.

This code is only 2.5 slower than calling localtime_r when uncontended
on haswell.

#include <pthread.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>

pthread_mutex_t l;

struct tm *localtime_rz(char *new, time_t *clockp, struct tm *resultp)
{
  pthread_mutex_lock (&l);
  char *old = strdup (getenv ("TZ"));
  if (strcmp(old,new))
    {
      setenv ("TZ", (char *) new, 1);
      tzset ();
    }
  struct tm *result = localtime_r (clockp, resultp);
  if (strcmp(old,new))
    {
      setenv ("TZ", old, 1);
      tzset ();
      free (old);
    }
  pthread_mutex_unlock (&l);
  return result;
}


int main(){
  int i;
  setenv("TZ", "GMT", 1);
  for (i=0;i<10000000;i++)
    {
      time_t c;
      struct tm p;
      //localtime_rz ("GMT", &c, &p);
      localtime_r (&c, &p);
    }
}                                                                                       


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]