@@ -40,15 +40,14 @@ public void CacheWrapperTest()
4040 [ TestMethod ]
4141 public void CacheWrapperEfficiencyTest ( )
4242 {
43- Console . WriteLine ( "��ʼCacheWrapper�첽���� " ) ;
43+ Console . WriteLine ( "Start CacheWrapper asynchronous test " ) ;
4444 var threadCount = 10 ;
4545 var finishCount = 0 ;
4646 List < Thread > threadList = new List < Thread > ( ) ;
4747 for ( int i = 0 ; i < threadCount ; i ++ )
4848 {
4949 var thread = new Thread ( ( ) =>
5050 {
51-
5251 var testClass = new TestClass ( )
5352 {
5453 ID = Guid . NewGuid ( ) . ToString ( ) ,
@@ -58,31 +57,26 @@ public void CacheWrapperEfficiencyTest()
5857
5958 var dtx = SystemTime . Now . DateTime ;
6059 var json = testClass . SerializeToCache ( ) ;
61- //Console.WriteLine(json);
62- Console . WriteLine ( $ "testClass.SerializeToCache ��ʱ��{ SystemTime . DiffTotalMS ( dtx ) } ms") ;
63-
60+ //Console.WriteLine(json);
61+ Console . WriteLine ( $ "testClass.SerializeToCache took: { SystemTime . DiffTotalMS ( dtx ) } ms") ;
6462
6563 dtx = SystemTime . Now . DateTime ;
6664 var obj = json . DeserializeFromCache < TestClass > ( ) ;
67- Console . WriteLine ( $ "json.DeserializeFromCache<TestClass> ��ʱ�� { SystemTime . DiffTotalMS ( dtx ) } ms") ;
65+ Console . WriteLine ( $ "json.DeserializeFromCache<TestClass> took: { SystemTime . DiffTotalMS ( dtx ) } ms") ;
6866 Assert . AreEqual ( obj . ID , testClass . ID ) ;
6967 Assert . AreEqual ( obj . Star , testClass . Star ) ;
7068 Assert . AreEqual ( obj . AddTime , testClass . AddTime ) ;
7169
7270 Console . WriteLine ( "" ) ;
73-
7471 finishCount ++ ;
7572 } ) ;
7673 threadList . Add ( thread ) ;
7774 }
78-
7975 threadList . ForEach ( z => z . Start ( ) ) ;
80-
8176 while ( finishCount < threadCount )
8277 {
83- //Waiting
78+ //Wait
8479 }
85-
8680 }
8781
8882 [ TestMethod ]
@@ -101,19 +95,17 @@ public void CacheWapper_VS_BinaryTest()
10195
10296 var dtx = SystemTime . Now . DateTime ;
10397 var json = testClass . SerializeToCache ( ) ;
104- //Console.WriteLine(json);
105- //Console.WriteLine($"testClass.SerializeToCache took {SystemTime.DiffTotalMS(dtx)}ms");
106-
98+ //Console.WriteLine(json);
99+ //Console.WriteLine($"testClass.SerializeToCache took: {SystemTime.DiffTotalMS(dtx)}ms");
107100 dtx = SystemTime . Now . DateTime ;
108101 var obj = json . DeserializeFromCache < TestClass > ( ) ;
109- //Console.WriteLine($"json.DeserializeFromCache<TestClass> took {SystemTime.DiffTotalMS(dtx)}ms");
102+ //Console.WriteLine($"json.DeserializeFromCache<TestClass> took: {SystemTime.DiffTotalMS(dtx)}ms");
110103 Assert . AreEqual ( obj . ID , testClass . ID ) ;
111104 Assert . AreEqual ( obj . Star , testClass . Star ) ;
112105 Assert . AreEqual ( obj . AddTime , testClass . AddTime ) ;
113-
114106 }
115107 var dt2 = SystemTime . Now . DateTime ;
116- Console . WriteLine ( $ "CacheWrapper���л� { count } �Σ�ʱ�䣺 { ( dt2 - dt1 ) . TotalMilliseconds } ms") ;
108+ Console . WriteLine ( $ "CacheWrapper serialized { count } times, time: { ( dt2 - dt1 ) . TotalMilliseconds } ms") ;
117109
118110 dt1 = SystemTime . Now . DateTime ;
119111 for ( int i = 0 ; i < count ; i ++ )
@@ -127,21 +119,16 @@ public void CacheWapper_VS_BinaryTest()
127119
128120 var dtx = SystemTime . Now . DateTime ;
129121 var serializedObj = StackExchangeRedisExtensions . Serialize ( testClass ) ;
130- //Note: This issue seems to be related to DateTimeOffset being converted to Object, which cannot be deserialized back to the original type
131-
132- //Console.WriteLine($"StackExchangeRedisExtensions.Serialize took {SystemTime.DiffTotalMS(dtx)}ms");
133-
122+ //Note: This method seems to convert DateTimeOffset objects to Object, making it impossible to deserialize them into original objects.
123+ //Console.WriteLine($"StackExchangeRedisExtensions.Serialize took: {SystemTime.DiffTotalMS(dtx)}ms");
134124 dtx = SystemTime . Now . DateTime ;
135- var containerBag = StackExchangeRedisExtensions . Deserialize < TestClass > ( ( RedisValue ) serializedObj ) ; //11ms
136- //Console.WriteLine($"StackExchangeRedisExtensions.Deserialize took {SystemTime.DiffTotalMS(dtx)}ms");
137-
125+ var containerBag = StackExchangeRedisExtensions . Deserialize < TestClass > ( ( RedisValue ) serializedObj ) ; //11ms
126+ //Console.WriteLine($"StackExchangeRedisExtensions.Deserialize took: {SystemTime.DiffTotalMS(dtx)}ms");
138127 Assert . AreEqual ( containerBag . AddTime . Ticks , testClass . AddTime . Ticks ) ;
139128 Assert . AreNotEqual ( containerBag . GetHashCode ( ) , testClass . GetHashCode ( ) ) ;
140-
141129 }
142130 dt2 = SystemTime . Now . DateTime ;
143- Console . WriteLine ( $ "StackExchangeRedisExtensions���л� { count } �Σ�ʱ�䣺{ ( dt2 - dt1 ) . TotalMilliseconds } ms") ;
144-
131+ Console . WriteLine ( $ "StackExchangeRedisExtensions serialized { count } times, time: { ( dt2 - dt1 ) . TotalMilliseconds } ms") ;
145132
146133 dt1 = SystemTime . Now . DateTime ;
147134 for ( int i = 0 ; i < count ; i ++ )
@@ -153,24 +140,19 @@ public void CacheWapper_VS_BinaryTest()
153140 AddTime = SystemTime . Now . DateTime ,
154141 } ;
155142
156- //Simulating CacheWrapper Type issue to test performance; needs to ensure no performance degradation
157- //testClass.Type = testClass.GetType();
158-
143+ //Simulate the additional workload of CacheWrapper's Type, compare efficiency, the main efficiency loss is in the reflection type
144+ //testClass.Type = testClass.GetType();
159145 var dtx = SystemTime . Now . DateTime ;
160146 var serializedObj = Newtonsoft . Json . JsonConvert . SerializeObject ( testClass ) ;
161- //Console.WriteLine($"StackExchangeRedisExtensions.Serialize took {SystemTime.DiffTotalMS(dtx)}ms");
162-
147+ //Console.WriteLine($"StackExchangeRedisExtensions.Serialize took: {SystemTime.DiffTotalMS(dtx)}ms");
163148 dtx = SystemTime . Now . DateTime ;
164- var containerBag = Newtonsoft . Json . JsonConvert . DeserializeObject < TestClass > ( serializedObj ) ; //11ms
165- //Console.WriteLine($"StackExchangeRedisExtensions.Deserialize took {SystemTime.DiffTotalMS(dtx)}ms");
166-
149+ var containerBag = Newtonsoft . Json . JsonConvert . DeserializeObject < TestClass > ( serializedObj ) ; //11ms
150+ //Console.WriteLine($"StackExchangeRedisExtensions.Deserialize took: {SystemTime.DiffTotalMS(dtx)}ms");
167151 Assert . AreEqual ( containerBag . AddTime . Ticks , testClass . AddTime . Ticks ) ;
168152 Assert . AreNotEqual ( containerBag . GetHashCode ( ) , testClass . GetHashCode ( ) ) ;
169-
170153 }
171154 dt2 = SystemTime . Now . DateTime ;
172- Console . WriteLine ( $ "Newtonsoft ���л������䣩 { count } �Σ�ʱ�䣺{ ( dt2 - dt1 ) . TotalMilliseconds } ms") ;
173-
155+ Console . WriteLine ( $ "Newtonsoft serialization (without reflection) { count } times, time: { ( dt2 - dt1 ) . TotalMilliseconds } ms") ;
174156
175157 dt1 = SystemTime . Now . DateTime ;
176158 for ( int i = 0 ; i < count ; i ++ )
@@ -182,24 +164,19 @@ public void CacheWapper_VS_BinaryTest()
182164 AddTime = SystemTime . Now . DateTime ,
183165 } ;
184166
185- //Simulating CacheWrapper Type issue to test performance; needs to ensure no performance degradation
167+ //Simulate the additional workload of CacheWrapper's Type, compare efficiency, the main efficiency loss is in the reflection type
186168 testClass . Type = testClass . GetType ( ) ;
187-
188169 var dtx = SystemTime . Now . DateTime ;
189170 var serializedObj = Newtonsoft . Json . JsonConvert . SerializeObject ( testClass ) ;
190- //Console.WriteLine($"StackExchangeRedisExtensions.Serialize took {SystemTime.DiffTotalMS(dtx)}ms");
191-
171+ //Console.WriteLine($"StackExchangeRedisExtensions.Serialize took: {SystemTime.DiffTotalMS(dtx)}ms");
192172 dtx = SystemTime . Now . DateTime ;
193- var containerBag = Newtonsoft . Json . JsonConvert . DeserializeObject < TestClass > ( serializedObj ) ; //11ms
194- //Console.WriteLine($"StackExchangeRedisExtensions.Deserialize took {SystemTime.DiffTotalMS(dtx)}ms");
195-
173+ var containerBag = Newtonsoft . Json . JsonConvert . DeserializeObject < TestClass > ( serializedObj ) ; //11ms
174+ //Console.WriteLine($"StackExchangeRedisExtensions.Deserialize took: {SystemTime.DiffTotalMS(dtx)}ms");
196175 Assert . AreEqual ( containerBag . AddTime . Ticks , testClass . AddTime . Ticks ) ;
197176 Assert . AreNotEqual ( containerBag . GetHashCode ( ) , testClass . GetHashCode ( ) ) ;
198-
199177 }
200178 dt2 = SystemTime . Now . DateTime ;
201- Console . WriteLine ( $ "Newtonsoft ���л�+���� { count } �Σ�ʱ�䣺{ ( dt2 - dt1 ) . TotalMilliseconds } ms") ;
202-
179+ Console . WriteLine ( $ "Newtonsoft serialization + reflection { count } times, time: { ( dt2 - dt1 ) . TotalMilliseconds } ms") ;
203180
204181 dt1 = SystemTime . Now . DateTime ;
205182 for ( int i = 0 ; i < count ; i ++ )
@@ -211,28 +188,22 @@ public void CacheWapper_VS_BinaryTest()
211188 AddTime = SystemTime . Now . DateTime ,
212189 } ;
213190
214- //Simulating CacheWrapper Type issue to test performance; needs to ensure no performance degradation
191+ //Simulate the additional workload of CacheWrapper's Type, compare efficiency, the main efficiency loss is in the reflection type
215192 Expression < Func < TestClass > > fun = ( ) => testClass ;
216- //Console.WriteLine(fun.Body.Type);
217-
193+ //Console.WriteLine(fun.Body.Type);
218194 testClass . Type = fun . Body . Type ;
219-
220195 var dtx = SystemTime . Now . DateTime ;
221196 var serializedObj = Newtonsoft . Json . JsonConvert . SerializeObject ( testClass ) ;
222- //Console.WriteLine($"StackExchangeRedisExtensions.Serialize took {SystemTime.DiffTotalMS(dtx)}ms");
223-
197+ //Console.WriteLine($"StackExchangeRedisExtensions.Serialize took: {SystemTime.DiffTotalMS(dtx)}ms");
224198 dtx = SystemTime . Now . DateTime ;
225- var containerBag = Newtonsoft . Json . JsonConvert . DeserializeObject < TestClass > ( serializedObj ) ; //11ms
226- //Console.WriteLine($"StackExchangeRedisExtensions.Deserialize took {SystemTime.DiffTotalMS(dtx)}ms");
199+ var containerBag = Newtonsoft . Json . JsonConvert . DeserializeObject < TestClass > ( serializedObj ) ; //11ms
200+ //Console.WriteLine($"StackExchangeRedisExtensions.Deserialize took: {SystemTime.DiffTotalMS(dtx)}ms");
227201 Assert . AreEqual ( typeof ( TestClass ) , containerBag . Type ) ;
228202 Assert . AreEqual ( containerBag . AddTime . Ticks , testClass . AddTime . Ticks ) ;
229203 Assert . AreNotEqual ( containerBag . GetHashCode ( ) , testClass . GetHashCode ( ) ) ;
230-
231204 }
232205 dt2 = SystemTime . Now . DateTime ;
233- Console . WriteLine ( $ "Newtonsoft ���л���Lambda�� { count } �Σ�ʱ�䣺{ ( dt2 - dt1 ) . TotalMilliseconds } ms") ;
234-
206+ Console . WriteLine ( $ "Newtonsoft serialization (Lambda) { count } times, time: { ( dt2 - dt1 ) . TotalMilliseconds } ms") ;
235207 }
236-
237208 }
238- }
209+ }
0 commit comments