Issue 3289: unnecessary call to time and localtime slows time.mktime (original) (raw)
Basically, time.mktime calls time and localtime, and then overwrites those results. Removing these unnecessary calls results in a fairly noticeable speedup, lower double-digit percentile improvements for applications that do time parsing, for example.
The patch below is for 2.5, but should apply to more recent versions.
diff --git a/Modules/timemodule.c b/Modules/timemodule.c index be02ec2..dad235a 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -599,8 +599,6 @@ time_mktime(PyObject *self, PyObject *tup) { struct tm buf; time_t tt;
tt = time(&tt);
buf = *localtime(&tt); if (!gettmarg(tup, &buf)) return NULL; tt = mktime(&buf);