Python time.h() Examples

The following are 4 code examples of time.h(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module time , or try the search function .
Example #1
Source File: blas.py    From D-VAE with MIT License 5 votes vote down vote up
def c_headers(self):
        # std.cout doesn't require the '%' symbol to print stuff...
        # so it works much better with python's string-substitution stuff.
        return ['<iostream>', '<time.h>', '<sys/time.h>'] 
Example #2
Source File: blas.py    From attention-lvcsr with MIT License 5 votes vote down vote up
def c_headers(self):
        # std.cout doesn't require the '%' symbol to print stuff...
        # so it works much better with python's string-substitution stuff.
        return ['<iostream>', '<time.h>', '<sys/time.h>'] 
Example #3
Source File: kernel_sys.py    From PyVM with MIT License 5 votes vote down vote up
def sys_clock_gettime(kernel: Kernel, clk_id: Uint, tp_addr: Uint):
    """
    int clock_gettime(clockid_t clk_id, struct timespec *tp);

    The functions clock_gettime() and clock_settime() retrieve and set
   the time of the specified clock clk_id.

   The res and tp arguments are timespec structures, as specified in
   <time.h>:

    struct timespec {
        time_t   tv_sec;        /* seconds */
        long     tv_nsec;       /* nanoseconds */
    };
    """

    struct_timespec = struct.Struct('<II')

    import time

    time_nanoseconds = int(time.time() * 1_000_000_000)  # Python 3.6 compatibility
    sec, nsec = time_nanoseconds // 1_000_000_000, time_nanoseconds % 1_000_000_000

    kernel.cpu.mem.set_bytes(tp_addr, struct_timespec.size, struct_timespec.pack(sec, nsec))

    return 0 
Example #4
Source File: mytools.py    From chat with MIT License 5 votes vote down vote up
def time_me(info="used", format_string="ms"):
    """Performance analysis - time

    Decorator of time performance analysis.
    性能分析——计时统计
    系统时间(wall clock time, elapsed time)是指一段程序从运行到终止,系统时钟走过的时间。
    一般系统时间都是要大于CPU时间的。通常可以由系统提供,在C++/Windows中,可以由<time.h>提供。
    注意得到的时间精度是和系统有关系的。
    1.time.clock()以浮点数计算的秒数返回当前的CPU时间。用来衡量不同程序的耗时,比time.time()更有用。
    time.clock()在不同的系统上含义不同。在UNIX系统上,它返回的是"进程时间",它是用秒表示的浮点数(时间戳)。
    而在WINDOWS中,第一次调用,返回的是进程运行的实际时间。而第二次之后的调用是自第一次
    调用以后到现在的运行时间。(实际上是以WIN32上QueryPerformanceCounter()为基础,它比毫秒表示更为精确)
    2.time.perf_counter()能够提供给定平台上精度最高的计时器。计算的仍然是系统时间,
    这会受到许多不同因素的影响,例如机器当前负载。
    3.time.process_time()提供进程时间。

    Args:
        info: Customize print info. 自定义提示信息。
        format_string: Specifies the timing unit. 指定计时单位,例如's': 秒,'ms': 毫秒。
            Defaults to 's'.
    """
    def _time_me(func):
        @wraps(func)
        def _wrapper(*args, **kwargs):
            start = time.clock()
            # start = time.perf_counter()
            # start = time.process_time()
            result = func(*args, **kwargs)
            end = time.clock()
            if format_string == "s":
                print("%s %s %s"%(func.__name__, info, end - start), "s")
            elif format_string == "ms":
                print("%s %s %s" % (func.__name__, info, 1000*(end - start)), "ms")
            return result
        return _wrapper
    return _time_me