Esempio n. 1
0
        private static void RunLoop <T>(
            int repeat,
            Action <object, ChunkedMemoryStream> serialize,
            Func <ChunkedMemoryStream, Type, object> deserialize,
            BenchType type,
            ChunkedMemoryStream ms,
            Func <int, T> factory) where T : IEquatable <T>
        {
            var  sw        = Stopwatch.StartNew();
            var  incorrect = 0;
            long size      = 0;

            for (int i = 0; i < repeat; i++)
            {
                ms.SetLength(0);
                var instance = factory(i);
                if (type == BenchType.None)
                {
                    continue;
                }
                serialize(instance, ms);
                size += ms.Position;
                if (type == BenchType.Both || type == BenchType.Check)
                {
                    ms.Position = 0;
                    var deser = (T)deserialize(ms, typeof(T));
                    if (type == BenchType.Check && !instance.Equals(deser))
                    {
                        incorrect++;
                        //throw new SerializationException("not equal");
                    }
                }
            }
            ReportStatsAndRestart(sw, size, incorrect);
        }
Esempio n. 2
0
 public Bench()
 {
     Cost = Application.rand.Next(100);
     BenchType[] types = Enum.GetValues(typeof(BenchType)).Cast <BenchType>().ToArray();
     Type = types[Application.rand.Next(types.Length)];
 }
Esempio n. 3
0
 void setBenchType(string value)
 {
     switch (value)
     {
         case "PUB":
             btype = BenchType.PUB;
             break;
         case "PUBSUB":
             btype = BenchType.PUBSUB;
             break;
         case "REQREP":
             btype = BenchType.REQREPLY;
             break;
         case "SUITE":
             btype = BenchType.SUITE;
             break;
         default:
             btype = BenchType.PUB;
             Console.WriteLine("No type specified.  Defaulting to PUB.");
             break;
     }
 }