信息发布→ 登录 注册 退出

lua中使用毫秒精度时间的方法

发布时间:2026-01-11

点击量:

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")

标签:# config  # ms  # update  # files  # luaforge  # http  # luasocket  # net  # LUAINC  # br  # releases  # lua  # 能到  # 不需  # 要到  # 可以使用  # 可以用  # 为你  # 下载地址  # 自带  # 使用毫秒精度时间  
在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!