Comparing: Switch() and If()
#5

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?

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);
Here's my results with the code above:
Код:
[21:05:52] 1: 227, 2: 103, 3: 102, 4: 101
_______________

I use them both. There's no difference really, only in the indentation.
Reply


Messages In This Thread
Comparing: Switch() and If() - by DeathOnaStick - 16.07.2010, 15:43
Re: Comparing: Switch() and If() - by Sergei - 16.07.2010, 16:14
Re: Comparing: Switch() and If() - by WackoX - 16.07.2010, 16:56
Re: Comparing: Switch() and If() - by DeathOnaStick - 16.07.2010, 17:07
Re: Comparing: Switch() and If() - by Finn - 16.07.2010, 18:05
Re: Comparing: Switch() and If() - by DeathOnaStick - 16.07.2010, 18:39

Forum Jump:


Users browsing this thread: 1 Guest(s)