lua中使用毫秒精度时间的方法
这篇文章主要介绍了lua中使用毫秒精度时间的方法,本文讲解使用luasocket库实现毫秒精度时间,需要的朋友可以参考下。lua自带的时间函数只能到秒的精度。为了统计到毫秒精度的时间,可以使用luasocket。下载地址http://files.luaforge.net/releases/luasocket/luasocket,编译安装的时候,你可能需要在源码包根目录下的config文件中指定LUAINC变量为你的lua路径。
代码如下:
local socket = require "socket"
local t0 = socket.gettime()
-- do something
local t1 = socket.gettime()
print("used time: "..t1-t0.."ms")
update:如果对精度的要求不需要到毫秒级别,可以用自带的os模块.精度为0.01秒。代码如下:
local s = os.clock()
local e = os.clock()
print("used time"..e-s.." seconds")
本文由 创作,采用 知识共享署名4.0 国际许可协议进行许可。本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名。最后编辑时间为: 2020/05/25 04:05