Readability matters way more than the 200 nanoseconds you might save/waste.
We are talking microseconds when someone might use a spellbook. It just
doesn't matter.
On Mar 17, 2014 9:53 AM, "Mark Samman" <notifications@github.com> wrote:

> In data/actions/scripts/other/spellbook.lua:
>
> > @@ -19,11 +19,11 @@ function onUse(cid, item, fromPosition, itemEx, toPosition)
> >  			if i ~= 1 then
> >  				line = "\n"
> >  			end
> > -			line = line .. "Spells for Level " .. spell.level .. "\n"
> > +			line = ("%sSpells for Level %s\n"):format(line, spell.level)
>
> I've done some benchmarking on this and using ".." to concatenate strings
> is faster than string.format, so only use string.format when the code
> becomes significantly easier to understand using it.
>
> Marks-MacBook-Air:string_concat mark$ time lua dotdot.lua
>
> real    0m0.853s
> user    0m0.849s
> sys 0m0.003s
> Marks-MacBook-Air:string_concat mark$ time lua format.lua
>
> real    0m1.014s
> user    0m1.010s
> sys 0m0.002s
> Marks-MacBook-Air:string_concat mark$ time luajit dotdot.lua
>
> real    0m0.684s
> user    0m0.680s
> sys 0m0.002s
> Marks-MacBook-Air:string_concat mark$ time luajit format.lua
>
> real    0m0.737s
> user    0m0.733s
> sys 0m0.003s
> Marks-MacBook-Air:string_concat mark$
>
> dotdot.lua:
>
> local x = 14294local y = -91284local another_str = " world"
> for i = 1, 1000000 do
>         local tmp_str = "hello "
>         tmp_str = tmp_str .. ": " .. x .. y .. another_strend
>
> format.lua (note that this was also optimized by caching the string.format
> function, which we don't usually do in our scripts, and it still performed
> worse):
>
> local x = 14294
> local y = -91284
> local another_str = " world"
> local string_format = string.format
>
> for i = 1, 1000000 do
>         local tmp_str = "hello "
>         tmp_str = string_format("%s: %d %d%s", tmp_str, x, y, another_str)
> end
>
> --
> Reply to this email directly or view it on GitHub<https://github.com/otland/forgottenserver/pull/604/files#r10659165>
> .
>