|
应该比控制台里的ping更能反映真实的游戏速度吧。。
用法:ping() 或 ping(检查次数),比如ping(20)
- function ping(times)
- require "wait"
- n = times or 4
- fmt = function(num)
- return string.format("%d 毫秒", num * 1000)
- end
- timeout = 20
- wait.make(function()
- local time_start = utils.timer()
- local time_pre = time_start
- local time_max = 0
- local time_min = -1
- local lost = 0
- local t = 0
- local time_now = 0
- SendNoEcho("set ping start")
- for i = 1, n do
- local l, w = wait.regexp("ping", timeout)
- if not l then lost = lost + 1 end
- time_now = utils.timer()
- t = time_now -time_pre
- time_pre = time_now
-
- if l then
- if t > time_max then time_max = t end
- if time_min == -1 then time_min = t end
- if t < time_min then time_min = t end
- end
- if i ~= n + 1 then
- SendNoEcho("set ping '" .. fmt(t) .. "'")
- end
- end
- local l, w = wait.regexp("ping", timeout)
- local time_end = utils.timer()
- local average = (time_now-time_start) / n
- print("已发送 = " .. n .. ", 丢失 = " .. lost .. " (" .. string.format("%d%%", lost / n * 100) .. ")")
- print("最短 = " .. fmt(time_min) .. ", 最长 = " .. fmt(time_max) .. ", 平均 = " .. fmt(average))
- end)
- end
复制代码
北大侠客行MUD,中国最好的MUD |
|