-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtable_random_overwrite.lua
More file actions
43 lines (40 loc) · 906 Bytes
/
Copy pathtable_random_overwrite.lua
File metadata and controls
43 lines (40 loc) · 906 Bytes
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
--[[
--- Benchmark complete
On Server
reps 20 rounds 10000
small old 4.6385350004698e-07
small new 1.2625500000013e-07
big old 3.1202909999735e-06
big new 1.2906200004807e-07
--]]
local rand = math.Rand
function tableRandom(t)
local rand_index = rand(1, #t)
return t[rand_index]
end
local small = {}
local big = {}
LuctusCompareOften(20,0.1,10000,{
{"",function()
small = {}
big = {}
for i=0,math.Rand(5,99) do
table.insert(small,math.random())
end
for i=0,math.Rand(100,1000) do
table.insert(big,math.random())
end
end},
{"small old",function()
return table.Random(small)
end},
{"small new",function()
return tableRandom(small)
end},
{"big old",function()
return table.Random(big)
end},
{"big new",function()
return tableRandom(big)
end},
})