def timeit(logger, fmt, threshold):
    from json import dumps
    import time

    def is_json(json_data):
        try:
            json_object = dumps(json_data, indent=4)
        except ValueError:
            return False
        else:
            return json_object

    def timereald(method):
        def timed(*args, **kw):
            start = time.clock()
            result = method(*args, **kw)
            end = time.clock()

            try:
                obj, value = args
                data = is_json(value) if False else value
            except Exception:
                data = is_json(args) if False else args

            sec = (end - start)
            sec_color = Colors.RED
            if sec <= threshold[0]:
                sec_color = Colors.BLUE
            elif sec <= threshold[1]:
                sec_color = Colors.GREEN

            if fmt == 'simple':
                logger.debug("\nName: %r\nClock: %s%2.8f%s sec\n" %
                             (method.__name__,
                              sec_color,
                              sec,
                              Colors.ENDC,
                              ))
            elif fmt == 'verbose':
                logger.debug(
                    "\nName: %r\nClock: %s%2.8f%s sec\nObj: %s\nkw: %s\n%s\n" %
                    (method.__name__,
                     sec_color,
                     sec,
                     Colors.ENDC,
                     obj,
                     kw,
                     data,
                     ))
            return result
        return timed
    return timereald
dataset/ETHPy150Open carlitux/deoplete-ternjs/rplugin/python3/deoplete/sources/deoplate_ternjs/profiler.py/timeit/original