forked from khalidsalomao/SimpleHelpers.Net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJsonSpeedTest.cs
103 lines (91 loc) · 3.61 KB
/
JsonSpeedTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ServiceStack.Text;
using PerformanceTest.Logging;
namespace PerformanceTest
{
public class JsonSpeedTest
{
static ILog logger = LogProvider.GetCurrentClassLogger ();
internal static void Test (int loopCount)
{
// warm up
logger.Info ("Warm up");
TestInternal (1);
logger.Info ("Real test");
TestInternal (loopCount);
}
internal static void TestInternal (int loopCount)
{
logger.Info ("Initializing 10.000 items");
var list = MockObjectGen.GetTestUserDefinition (10000, "group name test", true).ToList ();
var txt = new string[list.Count];
using (Benchmark.Start ("JsonSpeedTest.Newtonsoft.Serialize"))
{
for (var i = 0; i < loopCount; i++)
{
for (int i1 = 0; i1 < list.Count; i1++)
txt[i1] = Newtonsoft.Json.JsonConvert.SerializeObject (list[i1]);
}
}
using (Benchmark.Start ("JsonSpeedTest.Newtonsoft.Deserialize"))
{
for (var i = 0; i < loopCount; i++)
{
for (int i1 = 0; i1 < txt.Length; i1++)
Newtonsoft.Json.JsonConvert.DeserializeObject<PerformanceTest.MockObjectGen.MockUser> (txt[i1]);
}
}
using (Benchmark.Start ("JsonSpeedTest.fastJSON.Serialize"))
{
for (var i = 0; i < loopCount; i++)
{
for (int i1 = 0; i1 < list.Count; i1++)
txt[i1] = fastJSON.JSON.Instance.ToJSON (list[i1]);
}
}
using (Benchmark.Start ("JsonSpeedTest.fastJSON.Deserialize"))
{
for (var i = 0; i < loopCount; i++)
{
for (int i1 = 0; i1 < txt.Length; i1++)
fastJSON.JSON.Instance.ToObject <PerformanceTest.MockObjectGen.MockUser> (txt[i1]);
}
}
using (Benchmark.Start ("JsonSpeedTest.ServiceStack.Serialize"))
{
for (var i = 0; i < loopCount; i++)
{
for (int i1 = 0; i1 < list.Count; i1++)
txt[i1] = ServiceStack.Text.JsonSerializer.SerializeToString (list[i1]);
}
}
using (Benchmark.Start ("JsonSpeedTest.ServiceStack.Deserialize"))
{
for (var i = 0; i < loopCount; i++)
{
for (int i1 = 0; i1 < txt.Length; i1++)
ServiceStack.Text.JsonSerializer.DeserializeFromString<PerformanceTest.MockObjectGen.MockUser> (txt[i1]);
}
}
using (Benchmark.Start ("JsonSpeedTest.ServiceStack.Serialize [JSV]"))
{
for (var i = 0; i < loopCount; i++)
{
for (int i1 = 0; i1 < list.Count; i1++)
txt[i1] = ServiceStack.Text.TypeSerializer.SerializeToString (list[i1]);
}
}
using (Benchmark.Start ("JsonSpeedTest.ServiceStack.Deserialize [JSV]"))
{
for (var i = 0; i < loopCount; i++)
{
for (int i1 = 0; i1 < txt.Length; i1++)
ServiceStack.Text.TypeSerializer.DeserializeFromString<PerformanceTest.MockObjectGen.MockUser> (txt[i1]);
}
}
}
}
}