Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Roblox
GitHub Repository: Roblox/luau
Path: blob/master/bench/micro_tests/test_TableSort.lua
2725 views
1
local function prequire(name) local success, result = pcall(require, name); return success and result end
2
local bench = script and require(script.Parent.bench_support) or prequire("bench_support") or require("../bench_support")
3
4
local arr_months = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}
5
6
local arr_num = {}
7
for i=1,100 do table.insert(arr_num, math.sin(i)) end
8
9
local arr_numk = {}
10
for i=1,10000 do table.insert(arr_numk, math.sin(i)) end
11
12
function test(arr)
13
local t = table.create(#arr)
14
15
for i=1,1e6/#arr do
16
table.move(arr, 1, #arr, 1, t)
17
table.sort(t)
18
end
19
end
20
21
bench.runCode(function() test(arr_months) end, "table.sort: 12 strings")
22
bench.runCode(function() test(arr_num) end, "table.sort: 100 numbers")
23
bench.runCode(function() test(arr_numk) end, "table.sort: 10k numbers")
24
25