Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unnecessary call to time and localtime slows time.mktime #47539

Closed
notherjnelson mannequin opened this issue Jul 5, 2008 · 2 comments
Closed

unnecessary call to time and localtime slows time.mktime #47539

notherjnelson mannequin opened this issue Jul 5, 2008 · 2 comments
Labels
extension-modules C modules in the Modules dir performance Performance or resource usage

Comments

@notherjnelson
Copy link
Mannequin

notherjnelson mannequin commented Jul 5, 2008

BPO 3289
Nosy @facundobatista

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2008-07-05.19:35:59.871>
created_at = <Date 2008-07-05.16:13:28.552>
labels = ['extension-modules', 'performance']
title = 'unnecessary call to time and localtime slows time.mktime'
updated_at = <Date 2008-07-05.19:35:59.845>
user = 'https://bugs.python.org/notherjnelson'

bugs.python.org fields:

activity = <Date 2008-07-05.19:35:59.845>
actor = 'facundobatista'
assignee = 'none'
closed = True
closed_date = <Date 2008-07-05.19:35:59.871>
closer = 'facundobatista'
components = ['Extension Modules']
creation = <Date 2008-07-05.16:13:28.552>
creator = 'nother_jnelson'
dependencies = []
files = []
hgrepos = []
issue_num = 3289
keywords = []
message_count = 2.0
messages = ['69283', '69290']
nosy_count = 2.0
nosy_names = ['facundobatista', 'nother_jnelson']
pr_nums = []
priority = 'normal'
resolution = 'accepted'
stage = None
status = 'closed'
superseder = None
type = 'performance'
url = 'https://bugs.python.org/issue3289'
versions = ['Python 2.6', 'Python 2.5', 'Python 3.0', 'Python 3.1', 'Python 2.7']

@notherjnelson
Copy link
Mannequin Author

notherjnelson mannequin commented Jul 5, 2008

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);

@notherjnelson notherjnelson mannequin added extension-modules C modules in the Modules dir performance Performance or resource usage labels Jul 5, 2008
@facundobatista
Copy link
Member

Commited in r64745. Thanks for this patch!

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir performance Performance or resource usage
Projects
None yet
Development

No branches or pull requests

1 participant