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"
🗿 静态函数
| Returns | Name | Description | |
|---|---|---|---|
| boolean | IsEntityValid | 返回实体是否有效 | |
| number | Benchmark | 基准测试函数性能 |
IsEntityValid
返回实体是否有效
local ret = NanosUtils.IsEntityValid(entity)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| any | entity | Required parameter | 要验证的实体 |
Returns
| Type | Description |
|---|---|
| boolean | 如果实体有效 |
Benchmark
基准测试函数性能,并在控制台中输出经过的时间
local ret = NanosUtils.Benchmark(name, amount, func, args...)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | name | Required parameter | 要输出的基准测试名称 |
| number | amount | Required parameter | 循环的次数 |
| function | func | Required parameter | 要调用的函数 |
| any | args... | Required parameter | 要调用的函数的参数 |
Returns
| Type | Description |
|---|---|
| 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"