Efficiency -
Scenario - 17.01.2012
I wanted some additional opinions about this, perhaps a few sensible people could give me some help!
I currently have this code:
pawn Код:
stock bool:IsTruckerSkin(skinid)
{
switch(skinid)
{
case 4, 5, 24, 34, 73, 129 .. 134, 159, 161, 162, 182, 191, 196 .. 198, 201, 202: return true;
}
}
Would it be better to use this, or perhaps make an array of such skin ID's?
EDIT: And if I were to make an array, how would I use it? Probably an idiot question, but my mind isn't working right tonight!
Re: Efficiency -
2KY - 17.01.2012
I'm assuming an array would be much better than a switch, however, I could be wrong in this area. You could code both options and use
GetTickCount to figure out the quicker way of doing things. If you do end up doing so, please show the results here as I'm curious myself.
Re: Efficiency -
Lorenc_ - 17.01.2012
You're creating a 32 bit array once doing so, the current code you have is MORE efficient then having to create a array and do all the stuff inside there.
Just keep with that code, should be more faster as well.
Re: Efficiency -
2KY - 17.01.2012
Quote:
Originally Posted by Lorenc_
You're creating a 32 bit array once doing so, the current code you have is MORE efficient then having to create a array and do all the stuff inside there.
Just keep with that code, should be more faster as well.
|
I suppose we learn new things every day. Thanks for that bit of information.
Re: Efficiency -
Scenario - 17.01.2012
Quote:
Originally Posted by Lorenc_
You're creating a 32 bit array once doing so, the current code you have is MORE efficient then having to create a array and do all the stuff inside there.
Just keep with that code, should be more faster as well.
|
I was thinking this was more efficient (and possibly faster), but just wasn't sure. Thanks! By the way, say I were to put this into an array. How would I use the array as if it were a stock function?
Quote:
EDIT: And if I were to make an array, how would I use it? Probably an idiot question, but my mind isn't working right tonight!
|
Re: Efficiency -
Lorenc_ - 17.01.2012
Quote:
Originally Posted by RealCop228
I was thinking this was more efficient (and possibly faster), but just wasn't sure. Thanks! By the way, say I were to put this into an array. How would I use the array as if it were a stock function?
|
One way:
pawn Код:
new
bool: g_validskins[ 300 char ]
;
SetValidSkins( 4, 5, 24, 34, 73, 129, 130, 131, 132, 133 134, 159, 161, 162, 182, 191, 196, 197 198, 201, 202 );//gamemodeinit
stock SetValidSkins( ... )
{
new
iArgs = numargs( )
;
for( new i; i < iArgs; i++ )
{
g_validskins{ getarg( i ) } = true;
}
}
stock bool: IsTruckerSkin( skinid )
{
if( g_validskins{ skinid } == true ) return true;
return false;
}
Re: Efficiency -
-Prodigy- - 17.01.2012
Nvm.
Re: Efficiency -
Scenario - 17.01.2012
Oh nice. Thanks!
Re: Efficiency -
Kar - 17.01.2012
You guys are speaking of Memory Saving, not actual efficiency..
Why do you even care about the array with if checks vs the stock + switch case?
Just compare them.
Re: Efficiency -
Scenario - 17.01.2012
Quote:
Originally Posted by Kar
You guys are speaking of Memory Saving, not actual efficiency..
Why do you even care about the array with if checks vs the stock + switch case?
Just compare them.
|
Like I said, my mind isn't functioning properly tonight.