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

Use GetTickCount/GetTickCount64 instead of QueryPerformanceCounter for monotonic clock #58605

Closed
vstinner opened this issue Mar 24, 2012 · 7 comments
Labels
OS-windows stdlib Python modules in the Lib dir

Comments

@vstinner
Copy link
Member

BPO 14397
Nosy @malemburg, @loewis, @vstinner, @tjguk, @briancurtin

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 2012-04-04.00:18:28.681>
created_at = <Date 2012-03-24.10:44:41.119>
labels = ['library', 'OS-windows']
title = 'Use GetTickCount/GetTickCount64 instead of QueryPerformanceCounter for monotonic clock'
updated_at = <Date 2012-04-29.00:44:14.015>
user = 'https://github.com/vstinner'

bugs.python.org fields:

activity = <Date 2012-04-29.00:44:14.015>
actor = 'python-dev'
assignee = 'none'
closed = True
closed_date = <Date 2012-04-04.00:18:28.681>
closer = 'vstinner'
components = ['Library (Lib)', 'Windows']
creation = <Date 2012-03-24.10:44:41.119>
creator = 'vstinner'
dependencies = []
files = []
hgrepos = []
issue_num = 14397
keywords = []
message_count = 7.0
messages = ['156690', '156694', '156695', '156718', '156748', '157450', '159553']
nosy_count = 7.0
nosy_names = ['lemburg', 'loewis', 'vstinner', 'tim.golden', 'brian.curtin', 'Yury.Selivanov', 'python-dev']
pr_nums = []
priority = 'normal'
resolution = 'duplicate'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue14397'
versions = ['Python 3.3']

@vstinner
Copy link
Member Author

QueryPerformanceCounter() is not monotonic on a multiprocessor computer on Windows XP. Extract of its documentation:

"Remarks

On a multiprocessor computer, it should not matter which processor is called. However, you can get different results on different processors due to bugs in the basic input/output system (BIOS) or the hardware abstraction layer (HAL). To specify processor affinity for a thread, use the SetThreadAffinityMask function."

See also:
http://bytes.com/topic/python/answers/527849-time-clock-going-backwards

time.steady(strict-True) (or "time.monotonic()"? the function name is not decided yet :§)) should use GetTickCounter64(), or GetTickCounter().

GetTickCount64() was added to Windows Seven / Server 2008. GetTickCount() overflows after 49 days.

QueryPerformanceCounter() has a better resolution than
GetTickCount64 and so it's maybe better to keep it for time.steady(strict-False)?

@vstinner vstinner added stdlib Python modules in the Lib dir OS-windows labels Mar 24, 2012
@YurySelivanov
Copy link
Mannequin

YurySelivanov mannequin commented Mar 24, 2012

I vote for adding just one function to the 'time' module: monotonic(),
which should exist only if the host OS support it.

And I don't see the point of having 'steady()' at all.

@loewis
Copy link
Mannequin

loewis mannequin commented Mar 24, 2012

A monotonic clock is not suitable for measuring durations, as it may still jump forward. A steady clock will not.

@YurySelivanov
Copy link
Mannequin

YurySelivanov mannequin commented Mar 24, 2012

A monotonic clock is not suitable for measuring durations, as it may still jump forward. A steady clock will not.

Well, Victor's implementation of 'steady()' is just a tiny wrapper, which uses 'monotonic()' or 'time()' if the former is not available. Hence 'steady()' is a misleading name.

@malemburg
Copy link
Member

Yury Selivanov wrote:

Yury Selivanov <yselivanov@gmail.com> added the comment:

> A monotonic clock is not suitable for measuring durations, as it may still jump forward. A steady clock will not.

Well, Victor's implementation of 'steady()' is just a tiny wrapper, which uses 'monotonic()' or 'time()' if the former is not available. Hence 'steady()' is a misleading name.

Agreed.

I think time.monotonic() is a better name.

@vstinner
Copy link
Member Author

vstinner commented Apr 4, 2012

I'm closing this issue as a duplicate... of the PEP-418. See the python-dev mailing list for discussions on this PEP.

@vstinner vstinner closed this as completed Apr 4, 2012
@python-dev
Copy link
Mannequin

python-dev mannequin commented Apr 29, 2012

New changeset 76d2e0761d18 by Victor Stinner in branch 'default':
Issue bpo-14428, bpo-14397: Implement the PEP-418
http://hg.python.org/cpython/rev/76d2e0761d18

@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
OS-windows stdlib Python modules in the Lib dir
Projects
None yet
Development

No branches or pull requests

2 participants