marktime.py
Simple python module for mark time.
Inspired by two functions from node.js:
Main features:
- easy to use
- no external dependencies
- 100% test coverage
- works with Python 2.7 and 3.3
Usage
$ pip install marktimeimport marktime
marktime.start('some task')
marktime.start('some another task')
marktime.stop('some task').sec
8.757422924041748
marktime.stop('some another task').sec
14.805735111236572
marktime.duration('some another task').msec
14805.735111236572
marktime.start('some task # 3')
with marktime.stopwatch('some task # 4'):
marktime.time.sleep(1)
import json
print json.dumps(marktime.labels, indent=4)
{
"some another task": {
"duration": 14.805735111236572,
"start_time": 1370453758.064955,
"end_time": 1370453772.87069
},
"some task # 3": {
"start_time": 1370453892.025603,
"end_time": None
},
"some task # 4": {
"duration": 1.00120210647583,
"start_time": 1370638027.000799,
"end_time": 1370638028.002001
},
"some task": {
"duration": 8.757422924041748,
"start_time": 1370453753.185846,
"end_time": 1370453761.943269
}
}API
-
marktime.start (label, at=None)
-
label— marker label. String. Required. -
at— time to start the countdown. IfNonethen usestime.time().
-
-
marktime.stop (label, remove_from_labels=False, stop_once=True)
-
label— marker label. String. Required. -
at— time to stop the countdown. IfNonethen usestime.time() -
remove_from_labels— ifTruethenlabelremoved from global dictmarktime.labels. -
stop_once— ifFalseand the countdown for the certainlabelis allready stopped thet it stopped it again. And thereafter the duration for the certainlabelwill be increased.
-
-
marktime.duration (label, stop_it=True, stop_at=None)
-
label— marker label. String. Required. -
stop_it— ifTruethen the countdown for the certainlabelwill be stopped. IfFalseand the countdown for the certainlabelis not stopped then returnsNone. -
stop_at— passed intostopfunction ifstop_it==True
-
-
marktime.stopwatch (label) — context manager (
withstatement support) -
marktime.labels — global
dictthat stores all the labels for time markers.
License
See LICENSE file.