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: What Costs More?

Previous Thread :: Next Thread 
Quenty is online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
24 Mar 2012 10:46 PM
Changing an item's statistic to what it already is, or using an if statement..

Which would take more resources: (In super large loops)

Button.Visible = true

OR

if not Button.Visible then
Button.Visible = true
end
Report Abuse
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
24 Mar 2012 10:47 PM
Usnig an if statement would cost more, because ROBLOX already does checks. :P
Report Abuse
Quenty is online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
24 Mar 2012 10:51 PM
OK. Thanks. (How the heck did you figure that out?)

Also, how would I generate a map of a 10,000 x 10,000 area? Screen shots, etc. ??

ROBLOX stop rendering stuff far away.
Report Abuse
myrkos is not online. myrkos
Joined: 06 Sep 2010
Total Posts: 8072
24 Mar 2012 10:52 PM
>ROBLOX already does checks

What? No...

But the if statement still costs more because it's almost the same as writing, so in the case you do have to set the variable it costs twice as much.

In other languages like C++ it's true because on most processors reading is slower than writing.
Report Abuse
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
24 Mar 2012 10:59 PM
"How the heck did you figure that out?"

I ran some tests. I used loops and let it run all night long (I usually hate leaving my computer on while I'm not there, but I made an exception). The results made it obvious that they checked it.
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
25 Mar 2012 12:38 AM
[ Content Deleted ]
Report Abuse
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
25 Mar 2012 12:59 AM
"Roblox doesn't check it."

It does. And I remember Stravant said it does too, though I think he was just assuming it. Anyways, I ran tests and I did see a difference. Using an if statement to verify if it was already equal was slower than just setting it without checking.

"Don't EVER ask questions like these again."

I disagree. It starts discussion about scripting, which is always welcome. It certainly help to compensate for the spam.
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
25 Mar 2012 07:37 AM
[ Content Deleted ]
Report Abuse
popinman322 is not online. popinman322
Joined: 04 Mar 2009
Total Posts: 5184
25 Mar 2012 07:48 AM
Unless this optimization is within a loop, it won't matter much. Within a loop the tiny optimizations will eventually add up.

Loop iteration 1:
100 ms regained (We'll assume that this is the average)
Loop iteration 10:
1 second regained
Loop iteration 100:
10 seconds regained

And so on.

@Oysi

I have nothing to say to you.
Report Abuse
1Ra is not online. 1Ra
Joined: 02 May 2010
Total Posts: 2400
25 Mar 2012 07:49 AM
I almost always do this kind of thing:

Button.Visible = not Button.Visible
Report Abuse
Flurite is not online. Flurite
Joined: 03 Apr 2011
Total Posts: 5386
25 Mar 2012 08:03 AM
@1Ra,

y u post script that irrelevant?
Report Abuse
Candymaniac is not online. Candymaniac
Joined: 08 Oct 2009
Total Posts: 8985
25 Mar 2012 09:02 AM
@Quenty;

You know, you could always localize every brick within close proximity, and put every other brick into Lighting. I'm not sure if that'll help...

"Knowledge talks, wisdom listens."
Report Abuse
Varp is not online. Varp
Joined: 18 Nov 2009
Total Posts: 5333
25 Mar 2012 09:23 AM
"In other languages like C++ it's true because on most processors reading is slower than writing."

That's not really true beyond the primitives though, since comparison and assignment operators can become really expensive. Really, what you want to do is to minimize, given the time C it takes to compare and the time A it takes to assign and the probability P of the value being unique, you want to choose the lesser of the two following:

Use a comparison operator: C+A*P
Use only assignment: A

If comparison is more expensive than assignment, you shouldn't ever compare. If the probability of a value being unique is very high, comparison probably also isn't a good idea.
Report Abuse
nate890 is not online. nate890
Joined: 22 Nov 2008
Total Posts: 21686
25 Mar 2012 10:50 AM
I'd rather

Button.Visible=(not Button.Visible and true)
Report Abuse
Quenty is online. Quenty
Joined: 03 Sep 2009
Total Posts: 9316
25 Mar 2012 01:52 PM
I'm calling functions, so..

(Button.Visible and ShowButton or HideButton)() would do it. :D
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
25 Mar 2012 02:25 PM
>(Button.Visible and ShowButton or HideButton)()

You forgot the function.
Report Abuse
BlueTaslem is not online. BlueTaslem
Joined: 11 May 2008
Total Posts: 11060
25 Mar 2012 02:48 PM
Oysi:
Micro-optimization does matter. Stop saying it doesn't. An incredibly inefficient just-to-see-it-works code can be rewritten to work quickly by getting rid of all of the tiny unnecessary calls.


As for the thread, the if statement should be 'much' slower. I can't imagine a situation, though, where you would be doing that, and regardless, you shouldn't be; it's extra computation.
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
25 Mar 2012 03:21 PM
[ Content Deleted ]
Report Abuse
booing is not online. booing
Joined: 04 May 2009
Total Posts: 6594
25 Mar 2012 07:12 PM
Well, think about what you're doing.

workspace.Part.Anchored = false
Goes around to where I guess workspace.Part.Anchored would be stored and change it to false.
if workspace.Part.Anchored then
workspace.Part.Anchored = false
end
Starts an if statement
Finds the value of workspace.Part.Anchored
Compares it to true
If it is true then find where it is again and set it to false
Otherwise do nothing
Closes the if statement.
Probably not even close to what really happens, but you see the idea.
Report Abuse
stravant is not online. stravant
Forum Moderator
Joined: 22 Oct 2007
Total Posts: 2893
25 Mar 2012 07:23 PM
Regardless of whether it checks or not in most cases using the if statement will be significantly more expensive due to all of the extra inter-op that has to be done to get and then set the value of the property.

If it's a particularly expensive property such as setting the position of a part, then I would check it with a profile first, but in most cases where it's a cheap set that doesn't have to do much definitely go for simply setting it.
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