Efficiency
#1

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!
Reply
#2

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.
Reply
#3

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.
Reply
#4

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.
Reply
#5

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!

Reply
#6

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;
}
Reply
#7

Nvm.
Reply
#8

Oh nice. Thanks!
Reply
#9

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.
Reply
#10

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


Forum Jump:


Users browsing this thread: 4 Guest(s)