Thread Tools Display Modes
10-21-10, 04:35 AM   #1
Sideshow
A Flamescale Wyrmkin
 
Sideshow's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 103
Lua performance (arithmic and concatenation)

Hello

I constanly ask my self (and google) if there is no other way than this:
randomvar[arg][var][arg].y = randomvar[arg][var][arg].y + 1

I can find nothing about it, but why is there no other way, like:
randomvar[arg][var][arg].y += 1
And would it be 'faster' ?

Second: I read that the concatenation operator ".." is quite slow. What is a better way to do it. Table.concat? It is for a loop with 50 concats per seconds.

/run local begin = GetTime() for i=1,100000 do local str = "a" .. "b" .. "c" end print(GetTime()-begin)

/run local tconcat = table.concat local begin = GetTime() for i=1,100000 do local str = tconcat({"a","b","c"}) end print(GetTime()-begin)

The second one would be faster ? I can't test it right now

Last edited by Sideshow : 10-21-10 at 04:45 AM.
  Reply With Quote
10-21-10, 02:44 PM   #2
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
i checked out the times

no addons, chilllin in Dal

first line

0.013999999995576
0.013000000006286
0.013999999995576
0.013999999995576
0.013000000006286


second line

0.11500000001979
0.14100000000326
0.14200000002165
0.14199999999255
0.14299999998184

regualur concat seems faster... and looks pretty swift
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote
10-21-10, 03:23 PM   #3
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
string.format("%s%d%s..whatever", str1,num1,str2,etc) should be faster than string concatenation when you know you have a number.

In all other situations the simple concatenation is cheaper I believe.

Not my investigation, just remember a relevant discussion on wowace with tests over a large number of iterations.
  Reply With Quote
10-21-10, 08:02 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,324
You also have to consider additional overhead to using function calls. Examples, global variable access, local variable access, table indexing, etc.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
10-22-10, 02:21 AM   #5
Sideshow
A Flamescale Wyrmkin
 
Sideshow's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 103
Ok thanks.

I found out that, a loop of 1,000,000

200 .. 'K' takes 2.6 seconds
string.format("%i%s", 1, "K") takes 1 second



The big thing is offcourse concatenating numbers... When you have no numbers in your cnocatenation, it's better to use ..

Last edited by Sideshow : 10-22-10 at 02:23 AM.
  Reply With Quote
10-25-10, 02:33 PM   #6
Xinhuan
A Chromatic Dragonspawn
 
Xinhuan's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 174
It will be even faster if you do

local format = format
for k = 1, 1000000 do
format("%i%s", 1, "K")
end
__________________
Author of Postal, Omen3, GemHelper, BankItems, WoWEquip, GatherMate, GatherMate2, Routes and Cartographer_Routes
  Reply With Quote
10-25-10, 02:37 PM   #7
Sideshow
A Flamescale Wyrmkin
 
Sideshow's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 103
or

local format = format
for k = 1, 1000000 do
format("%iK", 1)
end


did my homework
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Lua performance (arithmic and concatenation)


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off