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

replace deprecated time.clock() by time.process_time() #225

Closed
wants to merge 1 commit into from

Conversation

aqualogy
Copy link

With the release of Python 3.8 the function time.clock() has been removed, after having been deprecated since Python 3.3:
What’s New In Python 3.8

Calls to time.clock() should be replaced by calls to either time.perf_counter() or time.process_time(), depending on requirements.

I searched through the code of grass and replaced all occurences of time.clock() with time.process_time().

@wenzeslaus
Copy link
Member

Do we need this to be Python 2 compatible? We won't be backporting it, so perhaps not. But also wrapping this would be easy, so perhaps worth it.

At this point, I don't know how to decide if time.perf_counter() would be more appropriate in some cases.

time.clock()

On Unix, return the current processor time as a floating point number expressed in seconds. The precision, and in fact the very definition of the meaning of “processor time”, depends on that of the C function of the same name.

On Windows, this function returns wall-clock seconds elapsed since the first call to this function, as a floating point number, based on the Win32 function QueryPerformanceCounter(). The resolution is typically better than one microsecond.

Deprecated since version 3.3, will be removed in version 3.8: The behaviour of this function depends on the platform: use perf_counter() or process_time() instead, depending on your requirements, to have a well defined behaviour.

time.perf_counter() → float

Return the value (in fractional seconds) of a performance counter, i.e. a clock with the highest available resolution to measure a short duration. It does include time elapsed during sleep and is system-wide. The reference point of the returned value is undefined, so that only the difference between the results of consecutive calls is valid.

New in version 3.3.

time.process_time() → float

Return the value (in fractional seconds) of the sum of the system and user CPU time of the current process. It does not include time elapsed during sleep. It is process-wide by definition. The reference point of the returned value is undefined, so that only the difference between the results of consecutive calls is valid.

New in version 3.3.

@petrasovaa
Copy link
Contributor

Thank you, I replaced this with #244, uses time.perf_counter(), although I am not entirely sure which one is better, it's used e.g. in timeit

@petrasovaa petrasovaa closed this Dec 6, 2019
@neteler neteler added this to the 7.8.3 milestone Dec 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants