This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: unnecessary call to time and localtime slows time.mktime
Type: performance Stage:
Components: Extension Modules Versions: Python 3.0, Python 3.1, Python 2.7, Python 2.6, Python 2.5
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: facundobatista, nother_jnelson
Priority: normal Keywords:

Created on 2008-07-05 16:13 by nother_jnelson, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg69283 - (view) Author: Jon Nelson (nother_jnelson) Date: 2008-07-05 16:13
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);
msg69290 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2008-07-05 19:35
Commited in r64745. Thanks for this patch!
History
Date User Action Args
2022-04-11 14:56:36adminsetgithub: 47539
2008-07-05 19:35:59facundobatistasetstatus: open -> closed
resolution: accepted
messages: + msg69290
nosy: + facundobatista
2008-07-05 16:13:28nother_jnelsoncreate