跳至正文
版本:bleeding-edge 🩸

NanosUtils

包含实用和辅助函数的表。


🎒 示例

(NanosUtils.Benchmark) Benchmarks a function
local arg1 = math.random()
local arg2 = math.random()

NanosUtils.Benchmark("My Heavy Operation", 1000, function(param1, param2)
-- Do some heavy operations here
local result = param1 * param2
end, arg1, arg2)

-- Outputs "Benchmark 'My Heavy Operation' (x1000) took 1.5ms"

🗿 静态函数

ReturnsNameDescription
booleanIsEntityValid返回实体是否有效
numberBenchmark基准测试函数性能

IsEntityValid

返回实体是否有效
local ret = NanosUtils.IsEntityValid(entity)

Parameters

TypeParameterDefaultDescription
anyentity Required parameter 要验证的实体

Returns

TypeDescription
boolean如果实体有效

Benchmark

基准测试函数性能,并在控制台中输出经过的时间
local ret = NanosUtils.Benchmark(name, amount, func, args...)

Parameters

TypeParameterDefaultDescription
stringname Required parameter 要输出的基准测试名称
numberamount Required parameter 循环的次数
functionfunc Required parameter 要调用的函数
anyargs... Required parameter 要调用的函数的参数

Returns

TypeDescription
number经过的时间(毫秒)
NanosUtils.Benchmark Examples
Benchmarks a function
local arg1 = math.random()
local arg2 = math.random()

NanosUtils.Benchmark("My Heavy Operation", 1000, function(param1, param2)
-- Do some heavy operations here
local result = param1 * param2
end, arg1, arg2)

-- Outputs "Benchmark 'My Heavy Operation' (x1000) took 1.5ms"