2010-07-27 04:09:10 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
ptime.py - Precision time function made os-independent (should have been taken care of by python)
|
|
|
|
Copyright 2010 Luke Campagnola
|
2019-08-17 03:16:01 +00:00
|
|
|
Distributed under MIT/X11 license. See license.txt for more information.
|
2010-07-27 04:09:10 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
import sys
|
2021-07-23 03:57:50 +00:00
|
|
|
import warnings
|
2019-07-02 11:01:32 +00:00
|
|
|
|
2021-08-02 16:02:11 +00:00
|
|
|
from time import perf_counter as clock
|
|
|
|
from time import time as system_time
|
2019-07-02 11:01:32 +00:00
|
|
|
|
2010-07-27 04:09:10 +00:00
|
|
|
START_TIME = None
|
|
|
|
time = None
|
|
|
|
|
|
|
|
def winTime():
|
|
|
|
"""Return the current time in seconds with high precision (windows version, use Manager.time() to stay platform independent)."""
|
2021-07-23 03:57:50 +00:00
|
|
|
warnings.warn(
|
|
|
|
"'pg.time' will be removed from the library in the first release following January, 2022. Use time.perf_counter instead",
|
|
|
|
DeprecationWarning, stacklevel=2
|
|
|
|
)
|
2020-07-17 06:53:19 +00:00
|
|
|
return clock() + START_TIME
|
2010-07-27 04:09:10 +00:00
|
|
|
|
|
|
|
def unixTime():
|
|
|
|
"""Return the current time in seconds with high precision (unix version, use Manager.time() to stay platform independent)."""
|
2021-07-23 03:57:50 +00:00
|
|
|
warnings.warn(
|
|
|
|
"'pg.time' will be removed from the library in the first release following January, 2022. Use time.perf_counter instead",
|
|
|
|
DeprecationWarning, stacklevel=2
|
|
|
|
)
|
2019-07-02 11:01:32 +00:00
|
|
|
return system_time()
|
2010-07-27 04:09:10 +00:00
|
|
|
|
2021-07-23 03:57:50 +00:00
|
|
|
|
2013-01-30 20:51:38 +00:00
|
|
|
if sys.platform.startswith('win'):
|
2019-07-02 11:01:32 +00:00
|
|
|
cstart = clock() ### Required to start the clock in windows
|
|
|
|
START_TIME = system_time() - cstart
|
2010-07-27 04:09:10 +00:00
|
|
|
|
|
|
|
time = winTime
|
|
|
|
else:
|
|
|
|
time = unixTime
|
|
|
|
|