Ejemplo n.º 1
0
        public void Just_how_fast_are_you()
        {
            ProtoBuf.Serializer.PrepareSerializer <SerializationTestMessage>();

            var message = new SerializationTestMessage
            {
                DecimalValue  = 123.45m,
                LongValue     = 098123213,
                BoolValue     = true,
                ByteValue     = 127,
                IntValue      = 123,
                DateTimeValue = new DateTime(2008, 9, 8, 7, 6, 5, 4),
                TimeSpanValue = TimeSpan.FromSeconds(30),
                GuidValue     = Guid.NewGuid(),
                StringValue   = "Chris's Sample Code",
                DoubleValue   = 1823.172
            };

            var            sendContext    = new InMemorySendContext <SerializationTestMessage>(message);
            ReceiveContext receiveContext = null;

            //warm it up
            for (var i = 0; i < 10; i++)
            {
                byte[] data = Serialize(sendContext);

                var transportMessage = new InMemoryTransportMessage(Guid.NewGuid(), data, Serializer.ContentType.MediaType,
                                                                    TypeMetadataCache <SerializationTestMessage> .ShortName);
                receiveContext = new InMemoryReceiveContext(new Uri("loopback://localhost/input_queue"), transportMessage, new ReceiveObservable(), Bus, PublishEndpointProvider);

                Deserialize <SerializationTestMessage>(receiveContext);
            }

            var timer = Stopwatch.StartNew();

            const int iterations = 50000;

            for (var i = 0; i < iterations; i++)
            {
                Serialize(sendContext);
            }

            timer.Stop();

            var perSecond = iterations * 1000 / timer.ElapsedMilliseconds;

            Console.WriteLine("Serialize: {0}ms, Rate: {1} m/s", timer.ElapsedMilliseconds, perSecond);


            timer = Stopwatch.StartNew();

            for (var i = 0; i < 50000; i++)
            {
                Deserialize <SerializationTestMessage>(receiveContext);
            }

            timer.Stop();

            perSecond = iterations * 1000 / timer.ElapsedMilliseconds;

            Console.WriteLine("Deserialize: {0}ms, Rate: {1} m/s", timer.ElapsedMilliseconds, perSecond);
        }
 public InMemoryReceiveContext(InMemoryTransportMessage message, ReceiveEndpointContext receiveEndpointContext)
     : base(message.DeliveryCount > 0, receiveEndpointContext)
 {
     _body    = message.Body;
     _message = message;
 }