And how does this work/why is this a good benchmark?

On 7/16/06, Hugh Perkins <[EMAIL PROTECTED]> wrote:

Just to check if there are any performance issues with using Reflective
introspection to run binary unmarshalling/marshalling, wrote a quick
benchmarking program.  On a 2GHz processor, this can handle about 20000
packets a second.

Here's the output from the code:

Packets unmarshalled: 0 Total time elapsed: 00:00:00.0156250
Packets unmarshalled: 10000 Total time elapsed: 00:00:00.5312500
Packets unmarshalled: 20000 Total time elapsed: 00:00:01.0468750
Packets unmarshalled: 30000 Total time elapsed: 00:00: 01.5625000
Packets unmarshalled: 40000 Total time elapsed: 00:00:02.0781250
Packets unmarshalled: 50000 Total time elapsed: 00:00:02.6093750
Packets unmarshalled: 60000 Total time elapsed: 00:00:03.1093750
Packets unmarshalled: 70000 Total time elapsed: 00:00: 03.6250000
Packets unmarshalled: 80000 Total time elapsed: 00:00:04.1093750
Packets unmarshalled: 90000 Total time elapsed: 00:00:04.6093750
Packets unmarshalled: 100000 Total time elapsed: 00:00:05.1093750
Packets unmarshalled: 110000 Total time elapsed: 00:00: 05.6250000
Packets unmarshalled: 120000 Total time elapsed: 00:00:06.1093750
Packets unmarshalled: 130000 Total time elapsed: 00:00:06.6093750
Packets unmarshalled: 140000 Total time elapsed: 00:00:07.0937500
 Packets unmarshalled: 150000 Total time elapsed: 00:00:07.6093750
Packets unmarshalled: 160000 Total time elapsed: 00:00:08.0937500
Packets unmarshalled: 170000 Total time elapsed: 00:00:08.5937500
Packets unmarshalled: 180000 Total time elapsed: 00:00: 09.0937500
Packets unmarshalled: 190000 Total time elapsed: 00:00:09.6093750
Packets unmarshalled: 200000 Total time elapsed: 00:00:10.0937500

Here's the benchmarking code:

using System;
using System.Collections;
using System.Reflection;


public class LLUUID
{
}

public class LLVector3
{
}

public class ImprovedInstantMessage
{
    public LLUUID FromAgentID = new LLUUID();
    public LLUUID ToAgentID = new LLUUID();
    public uint ParentEstateID = 0;
    public LLUUID RegionID  = new LLUUID();
    public LLVector3 Position = new LLVector3();
    public byte Offline  = 0;
    public byte Dialog   = 0;
    public LLUUID ID   = new LLUUID();
    public uint Timestamp  = 0;
    public string FromAgentName = "";
    public string Message  = "";
    public string BinaryBucket  = "";
}

class IntrospectionBenchmark
{
    public void Go()
    {
        DateTime start = DateTime.Now;

        ImprovedInstantMessage improvedinstantmessage = new
ImprovedInstantMessage();
        for( int i = 0; i < 1000000; i++ )
        {
            foreach( MemberInfo memberinfo in
improvedinstantmessage.GetType().GetMembers() )
            {
               // Console.WriteLine( memberinfo.Name  + " " +
memberinfo.MemberType.ToString () );
                if( memberinfo.MemberType == MemberTypes.Field )
                {
                    FieldInfo fi =
improvedinstantmessage.GetType().GetField( memberinfo.Name );
                    Type type = fi.FieldType;
                    if( type == typeof( LLUUID ) )
                    {
                        fi.SetValue( improvedinstantmessage, new LLUUID() );
                    }
                    else if( type == typeof( uint ) )
                    {
                        fi.SetValue( improvedinstantmessage, (uint)123 );
                    }
                    else if( type == typeof( LLVector3 ) )
                    {
                        fi.SetValue( improvedinstantmessage, new LLVector3()
);
                    }
                    else if( type == typeof( string ) )
                    {
                        fi.SetValue( improvedinstantmessage, "teststring" );
                    }
                }
            }
            if( i % 10000 == 0 )
            {
                Console.WriteLine( "Packets unmarshalled: " + i + " Total
time elapsed: " + DateTime.Now.Subtract( start ).ToString() );
            }
        }
    }
}

class entrypoint
{
    public static void Main( string[] args )
    {
        new IntrospectionBenchmark().Go();
    }
}


_______________________________________________
libsecondlife-dev mailing list
libsecondlife-dev@gna.org
https://mail.gna.org/listinfo/libsecondlife-dev





--
--Jesse

_______________________________________________
libsecondlife-dev mailing list
libsecondlife-dev@gna.org
https://mail.gna.org/listinfo/libsecondlife-dev

Reply via email to