You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
connecting_the_dots/co/gtimer.py

39 lines
857 B

5 years ago
import numpy as np
from . import utils
5 years ago
class StopWatch(utils.StopWatch):
def __del__(self):
print('=' * 80)
print('gtimer:')
total = ', '.join(['%s: %f[s]' % (k, v) for k, v in self.get(reduce=np.sum).items()])
print(f' [total] {total}')
mean = ', '.join(['%s: %f[s]' % (k, v) for k, v in self.get(reduce=np.mean).items()])
print(f' [mean] {mean}')
median = ', '.join(['%s: %f[s]' % (k, v) for k, v in self.get(reduce=np.median).items()])
print(f' [median] {median}')
print('=' * 80)
5 years ago
GTIMER = StopWatch()
5 years ago
def start(name):
GTIMER.start(name)
5 years ago
def stop(name):
GTIMER.stop(name)
5 years ago
class Ctx(object):
def __init__(self, name):
self.name = name
5 years ago
def __enter__(self):
start(self.name)
5 years ago
def __exit__(self, *args):
stop(self.name)