AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Optomization (https://forums.alliedmods.net/showthread.php?t=187849)

Liverwiz 06-18-2012 19:40

Optomization
 
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....

Bugsy 06-18-2012 20:20

Re: Optomization
 
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.

Exolent[jNr] 06-18-2012 20:32

Re: Optomization
 
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.

Liverwiz 06-18-2012 20:51

Re: Optomization
 
Ok. Thanks guys!

ConnorMcLeod 06-19-2012 00:36

Re: Optomization
 
Quote:

Originally Posted by Exolent[jNr] (Post 1731395)
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


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

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