16.07.2010, 18:05
How come for me it looks like switch is faster when it's about multiple statements and for single statement they're both the same speed?
Here's my results with the code above:
_______________
I use them both. There's no difference really, only in the indentation.
pawn Код:
new x = 1;
new check1 = GetTickCount();
for(new i; i < 1000; i++)
{
if(x == 0) x = 1;
else if(x == 1) print("abc");
else if(x == 2) x = 1;
else if(x == 3) x = 1;
else if(x == 4) x = 1;
}
new check2 = GetTickCount();
for(new i; i < 1000; i++)
{
switch(x)
{
case 0: x = 1;
case 1: print("abc");
case 2: x = 1;
case 3: x = 1;
case 4: x = 1;
}
}
new check3 = GetTickCount();
for(new i; i < 1000; i++)
{
if(x == 1) print("abc");
}
new check4 = GetTickCount();
for(new i; i < 1000; i++)
{
switch(x)
{
case 1: print("abc");
}
}
new check5 = GetTickCount();
printf("1: %d, 2: %d, 3: %d, 4: %d", check2-check1, check3-check2, check4-check3, check5-check4);
Код:
[21:05:52] 1: 227, 2: 103, 3: 102, 4: 101
I use them both. There's no difference really, only in the indentation.

