Time a method and print its duration after return
482480
def timer(func):
    
    name = func.__name__

    @wraps(func)
    def timed_func(self, *args, **kwargs):  # pylint: disable=missing-docstring
        _start = time.time()
        out = func(self, *args, **kwargs)
        self.log(2, '{0} took {1:.1f} sec'.format(name, time.time() - _start))
        return out

    return timed_func
89028
def count_time(function):
    
    @wraps(function)
    def _wrapper(*args, **kwargs):
        before = time()
        result = function(*args, **kwargs)
        diff = time() - before
        funcname = function.__name__
        print("{!r} func leave it {:.2f} ms to finish".format(funcname, diff))
        _wrapper.time = diff
        return result

    _wrapper.time = 0
    return _wrapper
1030300
def countdown(template, duration=datetime.timedelta(seconds=5)):
	
	now = datetime.datetime.now()
	deadline = now + duration
	remaining = deadline - datetime.datetime.now()
	while remaining:
		remaining = deadline - datetime.datetime.now()
		remaining = max(datetime.timedelta(), remaining)
		msg = template.format(remaining.total_seconds())
		print(msg, end=' ' * 10)
		sys.stdout.flush()
		time.sleep(.1)
		print('\b' * 80, end='')
		sys.stdout.flush()
	print()
1232012
def elapsed_time(self):
        """"""

        # Timer is running
        if self._t0 is not None:
            return self._time + self._get_time()
        else:
            return self._time
227614
def timeit(metric, func, *args, **kwargs):
    
    return _client.timeit(metric, func, *args, **kwargs)
1240149
def timeit(self, metric, func, *args, **kwargs):
        """"""
        return metrics.timeit(metric, func, *args, **kwargs)
1069922
def duration(self):
        
        d = self.for_attempt(self.cur_attempt)
        self.cur_attempt += 1
        return d
22468
def QA_util_calc_time(func, *args, **kwargs):
    
    _time = datetime.datetime.now()
    func(*args, **kwargs)
    print(datetime.datetime.now() - _time)
839537
def timemeter(msg=None):
    
    def _time_meter(fn):
        @functools.wraps(fn)
        def _wrapper(*args, **kwargs):
            mark = timeit.default_timer()
            result = fn(*args, **kwargs)
            cost = timeit.default_timer() - mark
            if msg:
                logger.info(msg, cost)
            else:
                logger.info('Execute <%s.%s> method cost %s seconds.', fn.__module__, fn.__name__, cost)
            return result
        return _wrapper
    return _time_meter
1019441
function duration (time) {
  var number = parseFloat(time)
  switch (unit(time)) {
    case null:
    case 'ms': return number
    case 's': return number * 1000
    case 'm': return number * 60000
    case 'h': return number * 3600000
    case 'd': return number * 86400000
    case 'w': return number * 604800000
    default: return null
  }
}
943115
def _duration(start, end):
    
    if start and end:
        if start > end:
            return None
        else:
            return end - start
    elif start:
        return time.time() - start
    else:
        return None
1132717
def print_total_timer():
    
    if len(_TOTAL_TIMER_DATA) == 0:
        return
    for k, v in six.iteritems(_TOTAL_TIMER_DATA):
        logger.info("Total Time: {} -> {:.2f} sec, {} times, {:.3g} sec/time".format(
            k, v.sum, v.count, v.average))
734298
def time_func(func):
    
    def timed(*args, **kwargs):
        ts = time.time()
        result = func(*args, **kwargs)
        secs = time.time() - ts
        ops_ps = kwargs.get('operations', secs) / secs
        print ("finc{} took: {} {:2.4f} operations/sec={:5.2f}".format(func.__name__, seconds_to_DHMS(secs), secs, ops_ps))
        return result
    return timed
634083
def _print_duration(self):
        ''''''
        duration = int(time.time() - self._start_time)
        self._print(datetime.timedelta(seconds=duration))
992614
function time(key, fn) {
        if (typeof data[key] === "undefined") {
            data[key] = 0;
        }

        return function(...args) {
            let t = process.hrtime();

            fn(...args);
            t = process.hrtime(t);
            data[key] += t[0] * 1e3 + t[1] / 1e6;
        };
    }
931170
def duration(self):
        
        if self._closed or \
                not self._result or \
                "duration" not in self._result:
            return -1
        return self._result.get("duration", 0)
1135413
def print_benchmark(self):
        """"""
        print('%-7.2f %s' % (self.elapsed, 'seconds elapsed'))
        if self.elapsed:
            for key in self._benchmark_keys:
                print('%-7d %s per second (%d total)' %
                      (self.counters[key] / self.elapsed, key,
                       self.counters[key]))