Example #1
0
        public void SerializeProtoObjects(int iterations)
        {
            ResetStopwatch("String Serialize");
            ResetStopwatch("String Deserialize");

            SimpleProtoObject simple;

            for (int i = 0; i < iterations; i++)
            {
                simple = new SimpleProtoObject()
                {
                    MyString = "Hello Franz", MyValue = i
                };

                StartStopwatch("String Serialize");
                DistributedCache.Insert("SerializationPerformanceTest" + i, simple, DateTime.UtcNow.AddSeconds(60));
                StopStopwatch("String Serialize");
            }

            for (int i = 0; i < iterations; i++)
            {
                StartStopwatch("String Deserialize");
                simple = DistributedCache.Get <SimpleProtoObject>("SerializationPerformanceTest" + i);
                StopStopwatch("String Deserialize");

                Assert.IsNotNull(simple);
                Assert.AreEqual(simple.MyValue, i);
                Assert.AreEqual(simple.MyString, "Hello Franz");
            }

            StopAndTraceStopwatch("String Serialize");
            StopAndTraceStopwatch("String Deserialize");
        }
Example #2
0
        public void SerializeObjectsInProcessCustomSerialization(int iterations)
        {
            ResetStopwatch("String Serialize");
            ResetStopwatch("String Deserialize");

            SimpleProtoObject simple;

            for (int i = 0; i < iterations; i++)
            {
                simple = new SimpleProtoObject()
                {
                    MyString = "Hello Franz", MyValue = i
                };

                StartStopwatch("String Serialize");
                System.Web.HttpRuntime.Cache.Insert("SerializationPerformanceTest" + i, ProtocolBufferSerialize <SimpleProtoObject>(simple), null, DateTime.UtcNow.AddSeconds(60), System.Web.Caching.Cache.NoSlidingExpiration);
                StopStopwatch("String Serialize");
            }

            for (int i = 0; i < iterations; i++)
            {
                StartStopwatch("String Deserialize");
                simple = ProtocolBufferDeserialize <SimpleProtoObject>((byte[])System.Web.HttpRuntime.Cache.Get("SerializationPerformanceTest" + i));
                StopStopwatch("String Deserialize");

                Assert.IsNotNull(simple);
                Assert.AreEqual(simple.MyValue, i);
                Assert.AreEqual(simple.MyString, "Hello Franz");
            }

            StopAndTraceStopwatch("String Serialize");
            StopAndTraceStopwatch("String Deserialize");
        }
Example #3
0
        public void ObjectTest()
        {
            SimpleProtoObject simple = new SimpleProtoObject()
            {
                MyString = "Hello Franz", MyValue = 100
            };

            DistributedCache.Insert("SimpleObject", simple, DateTime.UtcNow.AddSeconds(30));
            SimpleProtoObject cachedObject = DistributedCache.Get <SimpleProtoObject>("SimpleObject");
        }