Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 是否存在返回int类型的time.time()版本?_Python_Time_Int_Epoch_Timeit - Fatal编程技术网

Python 是否存在返回int类型的time.time()版本?

Python 是否存在返回int类型的time.time()版本?,python,time,int,epoch,timeit,Python,Time,Int,Epoch,Timeit,我的代码需要使用整数UNIX时间,但是time.time()不适合我的用例。它返回一个浮点,并使用math将其强制转换为int或floor。当使用timeit.timeit录制时,floor()花费的时间太长 timeit.timeit(lambda:time())的输出大约为.12秒,对于我的用例来说已经足够了,但不是整数。 timeit.timeit(lambda:int(time())的输出大约为.25秒,对于我的用例来说太长了。 timeit.timeit(lambda:math.flo

我的代码需要使用整数UNIX时间,但是
time.time()
不适合我的用例。它返回一个浮点,并使用math将其强制转换为int或floor。当使用timeit.timeit录制时,floor()花费的时间太长

timeit.timeit(lambda:time())
的输出大约为.12秒,对于我的用例来说已经足够了,但不是整数。
timeit.timeit(lambda:int(time())
的输出大约为.25秒,对于我的用例来说太长了。
timeit.timeit(lambda:math.floor(time())
大约为.36秒,是三个时间中最差的一个

计时非常重要,因此我更喜欢一些内置函数,它将UNIX时间返回为int而不是float

以下是我的代码片段:

def main():
    # The value of proceed goes up to 120.
    proceed = 1
    # timeout is some timestamp set at runtime, 2 days from the start of execution.
    while int(time()) <= timeout:
        # tps() uses int(time()), and this is what I want fixed.
        if proceed == tps():
            batchSend(tps())
            proceed += 1
        # These functions also use int(time())
        tocollect = mine()
        collect(tocollect)
def main():
#“继续”的值上升到120。
继续=1
#timeout是在运行时设置的时间戳,从执行开始算起2天。

而int(time())结果是我没有做作业。timeit.timeit()有一个默认的
number
值,设置为100万,因此实际值比我想象的要小得多。

您知道
timeit
多次运行测量的代码吗?“几个”可能是一百万,我不知道。阅读文档时,我没有选择时间它有一个默认值。如果我把.25秒除以1000000,我想那就足够了。