-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhook_many_vs_hook_once.lua
48 lines (43 loc) · 1.08 KB
/
hook_many_vs_hook_once.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
--This is a comparison between:
-- - Calling a hook for every player
-- - Calling a hook with a list of every player
--[[
--3 bots
--- Benchmark complete
On Server
reps 10 rounds 10000
single 9.2695600087609e-07
many 2.602249987649e-07
--40 bots
--- Benchmark complete
On Server
reps 10 rounds 10000
single 7.6739619999353e-06
many 3.9794599913876e-07
--]]
local t1 = {}
local t2 = {}
local t3 = {}
hook.Add("test_single","1",function(ply,num) t1[ply] = num end)
hook.Add("test_single","2",function(ply,num) t2[ply] = num end)
hook.Add("test_single","3",function(ply,num) t3[ply] = num end)
hook.Add("test_many","0",function(plys,num)
for k,ply in ipairs(plys) do
t1[ply] = num
t2[ply] = num
t3[ply] = num
end
end)
local input = ""
local allplayers = player.GetAll()
LuctusCompareOften(10,0.1,10000,{
{"",function() input = ranFloat() end},
{"single",function()
for k,ply in ipairs(allplayers) do
hook.Run("test_single",ply,input)
end
end},
{"many ",function()
hook.Run("test_many",allplayers,input)
end},
})