Raised This Month: $ Target: $400
 0% 

Optomization


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 06-18-2012 , 19:40   Optomization
Reply With Quote #1

Which is faster?

This:
Code:
static bool:flag flag = false

or This:
Code:
new bool:flag = false

In a function called say....in a EventDamage hook. (called a LOT)
Just kinda curious....
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-18-2012 , 20:20   Re: Optomization
Reply With Quote #2

In something like the Damage event I highly doubt you will see a difference, you could profile it to test but I wouldn't waste the time. If you were using PreThink or something called an insane amount of times then static would be better.
__________________

Last edited by Bugsy; 06-18-2012 at 20:25.
Bugsy is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-18-2012 , 20:32   Re: Optomization
Reply With Quote #3

With single-cell variables like that, it really doesn't matter much unless you are creating like 20 different ones.
Also, when you reinitialize the static variable, you use more CPU usage because it has to set the value again, so making it static doesn't necessarily save you much here. It's best used for arrays or lots of single-cell variables in a frequently called code block.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 06-18-2012 , 20:51   Re: Optomization
Reply With Quote #4

Ok. Thanks guys!
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-19-2012 , 00:36   Re: Optomization
Reply With Quote #5

Quote:
Originally Posted by Exolent[jNr] View Post
Also, when you reinitialize the static variable, you use more CPU usage because it has to set the value again
You do the same with 'new' ;)
http://forums.alliedmods.net/showthr...807#post523807

]Liverwiz
With damage event/forward, use new
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Reply



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

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

Forum Jump


All times are GMT -4. The time now is 06:10.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode