Which is better?
#1

Just wondering which method is 'better':

pawn Код:
stock GetVehicleTireStates(vehicleid, &FL, &BL, &FR, &BR)
{
    if(GetVehicleModel(vehicleid) == 0) return 0; // Vehicle doesn't exist
   
    new panels, doors, lights, tires;
    GetVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
   
    // Which is better
   
    // THIS
    FL = !!(tires & 0b1000);    // 8
    BL = !!(tires & 0b100);     // 4
    FR = !!(tires & 0b10);      // 2
    BR = !!(tires & 0b1);       // 1
    // !! turns the value in to a bool (1/0).
   
    // or THIS?
    BR = tires & 1;
    FR = tires >> 1 & 1;
    BL = tires >> 2 & 1;
    FL = tires >> 3 & 1;
    return 1;
}
They both have the exact same result.
Reply
#2

In my opinion the fastest way is better that the slow one.Which means I could use the second one.
Reply
#3

Actually I just benchmarked it with 1000000 iterations and the top method (!!) is faster by ~20 MS. Nothing I know but eh. If speed isn't something I could really base it on, which should I use? Can't decide :\
Reply
#4

I wonder what happens if you just assign the integer to a bool? If you prefix your function parameters with the bool: tag then the parser will probably do an implicit conversion. Or you may get a tag mismatch. Not sure. Can't test it right now because I'm not at home.
Reply
#5

The only reason I wanted it to be 0/1 is because I've always thought of true/false as 1/0. I guess that's not always the case and I should stop thinking that!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)