generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Efficiency

Previous Thread :: Next Thread 
1waffle1 is not online. 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 is not online. Sorcus
Forum Moderator
Joined: 29 Nov 2010
Total Posts: 3775
08 Nov 2011 09:32 PM
I choose B because its human readable.

~Sorcus
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
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 is not online. 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 is not online. 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
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
08 Nov 2011 09:39 PM
The second one definitely takes up more space.
Report Abuse
NecroBumpist is not online. NecroBumpist
Joined: 12 Sep 2010
Total Posts: 4198
08 Nov 2011 09:41 PM
How about you do benchmarks of both.
Report Abuse
SDuke524 is not online. 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 is not online. 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
Radioaktiivinen is not online. Radioaktiivinen
Joined: 25 Apr 2009
Total Posts: 18629
09 Nov 2011 08:12 AM
That looks complex, there must be a simpler way to do what youre doing!
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
09 Nov 2011 11:33 AM
[ Content Deleted ]
Report Abuse
HotThoth is not online. HotThoth
Forum Moderator
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 is not online. 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 is not online. 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 is not online. pwnedu46
Joined: 23 May 2009
Total Posts: 7534
09 Nov 2011 06:39 PM
^
Report Abuse
SDuke524 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image