bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] mktime UTC extremely slow (new in GAWK 4.2)


From: Andrew J. Schorr
Subject: Re: [bug-gawk] mktime UTC extremely slow (new in GAWK 4.2)
Date: Tue, 11 Dec 2018 11:49:25 -0500
User-agent: Mutt/1.5.21 (2010-09-15)

Hi,

Hmmm. The mktime_tz code looks like this:

static time_t
mktime_tz(struct tm *tm, const char *tzreq)
{
        time_t ret;
        char *tz = getenv("TZ");

        if (tz)
                tz = estrdup(tz, strlen(tz));
        if (setenv("TZ", tzreq, 1) < 0) {
                warning(_("setenv(TZ, %s) failed (%s)"), tzreq, 
strerror(errno));
                return -1;
        }
        tzset();
        ret = mktime(tm);
        if (tz) {
                if (setenv("TZ", tz, 1) < 0)
                        fatal(_("setenv(TZ, %s) restoration failed (%s)"), tz, 
strerror(errno));
                free(tz);
        } else {
                if (unsetenv("TZ") < 0)
                        fatal(_("unsetenv(TZ) failed (%s)"), strerror(errno));
        }
        tzset();
        return ret;
}

I guess these tzset/setenv/unsetenv calls may be expensive on Cygwin.

Does Cygwin have timegm? If so, perhaps that is faster. In reality, we are
always calling mktime_tz(& then, "UTC+0"), so not for an arbitrary TZ value.

In other words, would it help to apply the attached patch?
On Linux, the execution time for the 2 test cases is about the same
after applying this patch. Does it make any difference on Cygwin?

Regards,
Andy

Attachment: timegm.patch
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]