32 lines
663 B
Lua
32 lines
663 B
Lua
local function concat(strs)
|
|
local res = ""
|
|
for i = 1, #strs do
|
|
res = res .. strs[i]
|
|
end
|
|
|
|
return res
|
|
end
|
|
|
|
local function random_str()
|
|
return tostring(math.random(100000, 999999))
|
|
end
|
|
|
|
local strs = {}
|
|
for i = 1, 200000 do
|
|
strs[i] = random_str()
|
|
end
|
|
|
|
local time_start = os.clock()
|
|
concat(strs)
|
|
local own_concat_time = os.clock() - time_start
|
|
|
|
print("Own concat time: " .. own_concat_time)
|
|
|
|
time_start = os.clock()
|
|
_ = table.concat(strs)
|
|
local table_concat_time = os.clock() - time_start
|
|
|
|
print("table.concat time: " .. table_concat_time)
|
|
|
|
print(("table.concat was %f%s faster"):format(own_concat_time / table_concat_time * 100, "%"))
|