Staging
v0.5.0
https://foss.heptapod.net/mercurial/hgview
Raw File
Tip revision: df7af11a5ea2143444341e527210ba220bc45f40 authored by Carine Dengler on 11 February 2020, 15:15:42 UTC
[pkg] version 1.13.1
Tip revision: df7af11
decorators.py
# -*- coding: utf-8 -*-
"""
Some useful decorator functions
"""
from __future__ import print_function

import time

def timeit(func):
    """Decorator used to time the execution of a function"""
    def timefunc(*args, **kwargs):
        """wrapper"""
        t_1 = time.time()
        t_2 = time.clock()
        res = func(*args, **kwargs)
        t_3 = time.clock()
        t_4 = time.time()
        print("%s: %.2fms (time) %.2fms (clock)" %
              (func.__name__, 1000*(t_3 - t_2), 1000*(t_4 - t_1)))
        return res
    return timefunc
back to top