1waffle1
|
  |
| Joined: 16 Oct 2007 |
| Total Posts: 16381 |
|
|
| 08 Nov 2011 09:30 PM |
Which would be more efficient:
local a = [[chbqkbhc pppppppp XXXXXXXX XXXXXXXX XXXXXXXX PPPPPPPP CHBQKBHC]] for v in a:gmatch("[^\n]+") do if v == 6 then return v:sub(7,7) end end
Indexing one-character values in a multi-line string, or...
local a = {["A"] = {"c", "h", "b", "q", "k", "b", "h", "c"}, ["B"] = {"p", "p", "p", "p", "p", "p", "p", "p"}, ["C"] = {"X", "X", "X", "X", "X", "X", "X", "X"}, ["D"] = {"X", "X", "X", "X", "X", "X", "X", "X"}, ["E"] = {"X", "X", "X", "X", "X", "X", "X", "X"}, ["F"] = {"P", "P", "P", "P", "P", "P", "P", "P"}, ["G"] = {"C", "H", "B", "Q", "K", "B", "H", "C"}} return a["F"][7]
Indexing one-character values as an organized set of easily accessible subtables? |
|
|
| Report Abuse |
|
|
Sorcus
|
  |
 |
| Joined: 29 Nov 2010 |
| Total Posts: 3775 |
|
|
| 08 Nov 2011 09:32 PM |
I choose B because its human readable.
~Sorcus |
|
|
| Report Abuse |
|
|
|
| 08 Nov 2011 09:33 PM |
| Whichever is more or less efficient, I'd do the first one, because it's tons easier to read... |
|
|
| Report Abuse |
|
|
Slizerd
|
  |
| Joined: 15 Jun 2011 |
| Total Posts: 113 |
|
|
| 08 Nov 2011 09:35 PM |
I choose A because it's more human readable.
OT: Has anyone seen Crazyman32's Stranded game? It's got some epic camera work. |
|
|
| Report Abuse |
|
|
1waffle1
|
  |
| Joined: 16 Oct 2007 |
| Total Posts: 16381 |
|
|
| 08 Nov 2011 09:38 PM |
By efficiency, I mean processing speed.
Say I have this set of subtables, or this one string. I have a function that keeps changing the values around, and creating new sets and recursing multiple functions off of different variations of this set of data. Which would take up more space?
Then say I was doing calculations within one set of data. Which would be able to be indexed faster?
What if I wanted to do both? Which is best? |
|
|
| Report Abuse |
|
|
|
| 08 Nov 2011 09:39 PM |
| The second one definitely takes up more space. |
|
|
| Report Abuse |
|
|
|
| 08 Nov 2011 09:41 PM |
| How about you do benchmarks of both. |
|
|
| Report Abuse |
|
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 08 Nov 2011 09:44 PM |
>The second one definitely takes up more space.
But it's a lot more efficient to check. Also if he's doing this in roblox, the first one wouldn't really even be an option due to roblox not reading line breaks. |
|
|
| Report Abuse |
|
|
1waffle1
|
  |
| Joined: 16 Oct 2007 |
| Total Posts: 16381 |
|
|
| 08 Nov 2011 09:45 PM |
"the first one wouldn't really even be an option due to roblox not reading line breaks." false
a:gmatch("[^\n]+") |
|
|
| Report Abuse |
|
|
|
| 09 Nov 2011 08:12 AM |
| That looks complex, there must be a simpler way to do what youre doing! |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
HotThoth
|
  |
 |
| Joined: 24 Aug 2010 |
| Total Posts: 1176 |
|
|
| 09 Nov 2011 12:50 PM |
| Perhaps we have different definitions of human readable, or readable, or human. But to me, the second one is far more readable (even more so if you put the different '["C"] = {}...' parts on different lines). The second one probably is faster, for the reasons oysi said, but don't forget that indexing tables by keys is not really a 0-cost operation. |
|
|
| Report Abuse |
|
|
Davidii
|
  |
| Joined: 17 Jul 2008 |
| Total Posts: 1282 |
|
|
| 09 Nov 2011 06:07 PM |
| EFFICIENCY!? HA! WE DON'T NEED NO STINKIN' EFFICIENCY! |
|
|
| Report Abuse |
|
|
1waffle1
|
  |
| Joined: 16 Oct 2007 |
| Total Posts: 16381 |
|
|
| 09 Nov 2011 06:16 PM |
| right. because we all know how lightning fast roblox processes. |
|
|
| Report Abuse |
|
|
pwnedu46
|
  |
| Joined: 23 May 2009 |
| Total Posts: 7534 |
|
| |
|
SDuke524
|
  |
| Joined: 29 Jul 2008 |
| Total Posts: 6267 |
|
|
| 09 Nov 2011 10:35 PM |
>Roblox does read line breaks. Last time I checked, anyway. It's the output that doesn't take line breaks.
I had used them awhile ago for a sort of wiki gui thingy that I made awhile ago however, they didn't read the linebreaks so I just converted them to tables from php ( just because I was still learning PHP at the time and it was easier to open, no real big reason behind that ) and then just went off indexes. Although I could have just been doing it really wrong, I don't know. |
|
|
| Report Abuse |
|
|