File: ptime.py

package info (click to toggle)
python-pyqtgraph 0.11.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,684 kB
  • sloc: python: 45,678; makefile: 115; ansic: 40
file content (36 lines) | stat: -rw-r--r-- 1,012 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
"""
ptime.py -  Precision time function made os-independent (should have been taken care of by python)
Copyright 2010  Luke Campagnola
Distributed under MIT/X11 license. See license.txt for more information.
"""


import sys

if sys.version_info[0] < 3:
    from time import clock
    from time import time as system_time
else:
    from time import perf_counter as clock
    from time import time as system_time

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)."""
    return clock() + START_TIME

def unixTime():
    """Return the current time in seconds with high precision (unix version, use Manager.time() to stay platform independent)."""
    return system_time()

if sys.platform.startswith('win'):
    cstart = clock()  ### Required to start the clock in windows
    START_TIME = system_time() - cstart
    
    time = winTime
else:
    time = unixTime