View Single Post
03-31-09, 10:42 AM   #24
Aezay
A Theradrim Guardian
 
Aezay's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2007
Posts: 66
I completely forgot I had a lua5.1.exe lying around, so I just ran your code and come up with this, same results really, just faster. What did you use to run the code in?
Code:
1  multi line assign took 2.01600 secs
2  1 line assign took 2.54600 secs

Using your benchmark code, I tried running this to see which was fastest. It is more or less a copy/paste from one of my addons, from an OnUpdate script on a timer.
Code:
local text;
local showTotalTime = false;
local timeLeft, endTime;
local duration = 60;

local function FormatTime(sec)
	if (abs(sec) <= 60) then
		return string.format("%.1f",sec);
	else
		return string.format("%d:%.2d",sec / 60,abs(sec) % 60);
	end
end

endTime = clock() + duration;
bench("empty string concat",function()
	timeLeft = (endTime - clock());
	text = FormatTime(timeLeft)..(showTotalTime and " / "..duration or "");
end);

endTime = clock() + duration;
bench("no concat",function()
	timeLeft = (endTime - clock());
	text = showTotalTime and FormatTime(timeLeft).." / "..duration or FormatTime(timeLeft);
end);
To my surprise it didn't really matter which way it's done, I guess that is because the concat of an empty string is on the same line as the FormatTime call, and thus is done in the same go, meaning it wont actually create a new Lua string.
Code:
1  no concat took 13.15700 secs
2  empty string concat took 13.21800 secs
Setting the showTotalTime to true produces these results, which again is pretty much the same.
Code:
1  no concat took 23.56300 secs
2  empty string concat took 24.56200 secs

Last edited by Aezay : 03-31-09 at 11:24 AM.
  Reply With Quote