awsumben13, on 07 September 2015 - 04:32 PM, said:
you really seem to know your stuff in this case
Posted 14 September 2015 - 07:24 AM
Posted 14 September 2015 - 05:27 PM
awsumben13, on 07 September 2015 - 04:32 PM, said:
local s = "a" .. "b" .. "c" .. "d" .. "e"
-- will execute faster than
local s = table.concat { "a", "b", "c", "d", "e" }
local s = "" for i = 1, n do s = s .. v endDon't do this! Lua (C-Lua at least) takes time to make sure you're not duplicating strings. When you create a string, it will check every other string in existence, and if it is equal to that string, use that instead of the new one. Absolutely no idea why it does this, but it does. This is a really slow operation, so creating strings repeatedly (like in the above example) is slow. In that case, using table.concat() is a lot better:
local t = {}
for i = 1, n do
t[i] = v
end
local s = table.concat( t )
You'll notice ridiculous speed increases by doing this.Posted 14 September 2015 - 08:02 PM
blunty666, on 14 September 2015 - 05:27 PM, said:
awsumben13, on 07 September 2015 - 04:32 PM, said:
Posted 15 September 2015 - 01:28 AM
local minElements, maxElements, word, reps, counter = 1, 200, "\"asdf\"", 1000000, 0
print("Test: "..word..".."..word..".."..word.." vs table.concat()")
repeat
local elements, curElements = {}, math.floor((maxElements - minElements) / 2 + minElements)
for i = 1, curElements do elements[i] = word end
local func1 = loadstring("local t = os.clock() for i = 1, "..reps.." do local s = "..table.concat(elements,"..").." end return os.clock() - t")()
sleep(0)
local func2 = loadstring("local e = {"..table.concat(elements,",").."} local t = os.clock() for i = 1, "..reps.." do local s = table.concat(e) end return os.clock() - t")()
sleep(0)
counter = counter + 1
print("Set "..counter..", "..curElements.." elements: "..func1.."s (..), "..func2.."s (concat)")
if func1 > func2 then maxElements = curElements else minElements = curElements end
until func1 == func2 or minElements == maxElements
Posted 11 January 2016 - 03:10 PM
Edited by Wergat, 11 January 2016 - 03:10 PM.
Posted 11 January 2016 - 04:05 PM
SquidDev, on 14 April 2015 - 03:09 PM, said:
Quote
Quote
Edited by SquidDev, 11 January 2016 - 04:06 PM.
Posted 12 January 2016 - 12:24 AM
Wergat, on 11 January 2016 - 03:10 PM, said:
-- Using t.amount -- instead of #t.elementsIf i use the cached version X times, does it become faster?
Wergat, on 11 January 2016 - 03:10 PM, said:
Wergat, on 11 January 2016 - 03:10 PM, said:
local pos = math.abs
Posted 23 January 2016 - 09:50 AM
Posted 23 January 2016 - 10:35 AM
HDeffo, on 23 January 2016 - 09:50 AM, said:
Posted 23 January 2016 - 12:10 PM
Edited by Bomb Bloke, 24 January 2016 - 12:20 AM.
Posted 23 January 2016 - 06:29 PM
Posted 24 January 2016 - 12:16 AM
Posted 24 January 2016 - 06:34 PM
Posted 11 July 2016 - 03:20 PM
-- Saving the type for i = 1, #tab do local typ = type(tab[i]) if typ == 'table' then elseif typ == 'function' then <...> end -- predeclaring a var local typ; for i = 1, #tab do typ = type(tab[i]) if typ == 'table' then elseif typ == 'function' then <...> end -- Asking the type every time for i = 1, #tab do if type(tab[i]) == 'table' then elseif type(tab[i]) == 'function' then <...> end
Posted 11 July 2016 - 03:43 PM
local t = type( x ) print( t == v )
print( type( x ) == v )
Posted 11 July 2016 - 04:40 PM
Exerro, on 11 July 2016 - 03:43 PM, said:
local t = type( x ) print( t == v )
print( type( x ) == v )
Posted 11 July 2016 - 07:14 PM
Edited by CrazedProgrammer, 11 July 2016 - 07:14 PM.
Posted 11 July 2016 - 10:58 PM
Posted 12 July 2016 - 12:31 AM
Edited by Bomb Bloke, 12 July 2016 - 12:32 AM.
0 members, 1 guests, 0 anonymous users