[Mono-bugs] [Bug 655380] String switch statement runs 5x slower on iPhone if compared to simple list of if statements

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Nov 23 03:44:31 EST 2010


https://bugzilla.novell.com/show_bug.cgi?id=655380

https://bugzilla.novell.com/show_bug.cgi?id=655380#c7


--- Comment #7 from Marek Safar <msafar at novell.com> 2010-11-23 08:44:30 UTC ---
It was quick test last night, so I have done another run this morning

Test program based on IPhone test cases

using System;
using System.Diagnostics;

class C
{
    static void Main()
    {
        const int iterations = 1000000;
        var sw = new Stopwatch ();
        sw.Start ();
        for( int tryI = 0 ; tryI < iterations ; ++tryI )
        {
            CheckLongSwitchString("Update");
            CheckLongSwitchString("Dummy");
            CheckLongSwitchString("Dummy");
            CheckLongSwitchString("Update");
        }
        sw.Stop ();
        Console.WriteLine ("Switch " + sw.ElapsedMilliseconds.ToString ());

        sw.Reset ();
        sw.Start ();
        for( int tryI = 0 ; tryI < iterations ; ++tryI )
        {
            CheckLongIfString("Update");
            CheckLongIfString("Dummy");
            CheckLongIfString("Dummy");
            CheckLongIfString("Update");
        }
        sw.Stop ();
        Console.WriteLine ("If " + sw.ElapsedMilliseconds.ToString ());
        Console.WriteLine (counter);
    }

    static int counter = 0;

    static void CheckLongSwitchString(string arg)
    {
        switch(arg)
        {
        case "Start":
            counter = 1;
            break;
        case "Update":
            counter = 2;
            break;
        case "Special":
            counter = 2;
            break;
        default:
            counter = 1;
            break;
        }
    }

    static void CheckLongIfString(string arg)
    {
        if( arg == "Start" )
            counter = 1;
        else if( arg == "Update" )
            counter = 2;
        else if( arg == "Special" )
            counter = 2;
        else
            counter = 1;
    }    
}

on my x86-32 with sgen

Switch 289
If 188

nowhere near observed ~5 slowdown on IPhone (I know, I had to bump the number
of iterations to actually see any numbers).

I could implement if/else for smaller counts but it makes sense only when our
if comparison becomes as fast as .net one.

BTW, same program on .net 4 (compiled with dmcs) gives

Switch 279
If 78

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list