-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
64 changed files
with
9,765 additions
and
5,634 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,119 @@ | ||
using System.Data; | ||
using System; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using STLib.Json; | ||
|
||
namespace STLib.Json.Test | ||
{ | ||
internal class Program | ||
public class UserInfo | ||
{ | ||
[STJson(STJsonSerilizaMode.All)] | ||
public class Student | ||
{ | ||
[STJsonProperty("test_name")] | ||
public string Name; | ||
[STJsonProperty] | ||
public int Age; | ||
public Gender Gender; | ||
[STJsonProperty] // optional | ||
public List<string> Hobby; | ||
} | ||
public string Name { get; set; } | ||
public string Github { get; set; } | ||
public string[] Language { get; set; } | ||
public Address Address { get; set; } | ||
} | ||
|
||
public enum Gender | ||
{ | ||
Male, Female | ||
} | ||
public class Address | ||
{ | ||
public string Country { get; set; } | ||
public string Province { get; set; } | ||
public string City { get; set; } | ||
} | ||
|
||
static void Main(string[] args) { | ||
DataTable dt = new DataTable(); | ||
dt.Columns.Add("name"); | ||
dt.Columns.Add("age", typeof(int)); | ||
dt.Columns.Add("is_boy", typeof(bool)); | ||
for (int i = 0; i < 10; i++) { | ||
DataRow dr = dt.NewRow(); | ||
dr["name"] = "test"; | ||
dr["age"] = 10; | ||
dr["is_boy"] = i % 2 == 0; | ||
dt.Rows.Add(dr); | ||
} | ||
internal class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
//var obj_test = STJsonTestObject.CreateTestObject(); | ||
var type = typeof(UserInfo); | ||
var obj_test = new UserInfo() | ||
{ | ||
Name = "DebugST", | ||
Github = "https://github.com/DebugST", | ||
Language = new string[] { "C#", "JS", "..." }, | ||
Address = new Address() | ||
{ | ||
Country = "China", | ||
Province = "GuangDong", | ||
City = "ShenZhen" | ||
} | ||
}; | ||
string str_json, str_temp; | ||
Console.WriteLine("========================================"); | ||
Console.WriteLine(STJson.Serialize(obj_test)); | ||
Console.WriteLine("========================================"); | ||
|
||
var str = STJson.Serialize(dt, 4); | ||
Console.WriteLine(str); | ||
Console.WriteLine("[CHECK_IS_SAME]"); | ||
|
||
var stu = new Student() { | ||
Name = "Tom", | ||
Age = 20, | ||
Hobby = new List<string>() { "sing", "dance" } | ||
}; | ||
object obj = STJsonTestObject.CreateTestObject(); | ||
Console.WriteLine(STJson.Serialize(obj, 4)); | ||
str_json = JsonConvert.SerializeObject(obj_test); | ||
str_temp = JsonConvert.SerializeObject(JsonConvert.DeserializeObject<UserInfo>(str_json)); | ||
Console.WriteLine("Newtonsoft : " + (str_temp == str_json)); | ||
|
||
str = STJson.Serialize(stu, 4); | ||
Console.WriteLine(str); | ||
stu = STJson.Deserialize<Student>(str); | ||
str_json = STJson.Serialize(obj_test); | ||
str_temp = STJson.Serialize(STJson.Deserialize<UserInfo>(str_json)); | ||
Console.WriteLine("STJson : " + (str_temp == str_json)); | ||
|
||
Console.WriteLine(STJson.Serialize(new System.Drawing.Rectangle(10, 10, 100, 100))); | ||
var sw = new System.Diagnostics.Stopwatch(); | ||
|
||
Console.WriteLine(STJson.FromObject(stu).Select("..").ToString(4)); | ||
int n_counter = 50000; | ||
System.Threading.Thread.Sleep(5000); | ||
Console.WriteLine("========================================"); | ||
Console.WriteLine("[Deserialize To Linq] - " + n_counter); | ||
sw.Reset(); | ||
sw.Start(); | ||
for (int i = 0; i < n_counter; i++) { | ||
JsonConvert.DeserializeObject<JObject>(str_json); | ||
} | ||
sw.Stop(); | ||
Console.WriteLine("Newstonoft : " + sw.ElapsedMilliseconds); | ||
|
||
//str = STJson.Serialize(obj, 4); | ||
//var sw = new System.Diagnostics.Stopwatch(); | ||
//int nCount = 10000; | ||
sw.Reset(); | ||
sw.Start(); | ||
for (int i = 0; i < n_counter; i++) { | ||
STJson.Deserialize(str_json); | ||
} | ||
sw.Stop(); | ||
Console.WriteLine("STJson : " + sw.ElapsedMilliseconds); | ||
// ==================================================================================================== | ||
System.Threading.Thread.Sleep(5000); | ||
Console.WriteLine("========================================"); | ||
Console.WriteLine("[Deserialize To object] - " + n_counter); | ||
sw.Reset(); | ||
sw.Start(); | ||
for (int i = 0; i < n_counter; i++) { | ||
JsonConvert.DeserializeObject<UserInfo>(str_json); | ||
} | ||
sw.Stop(); | ||
Console.WriteLine("Newstonoft : " + sw.ElapsedMilliseconds); | ||
|
||
//while (true) { | ||
// Console.ReadKey(); | ||
// Console.WriteLine("==="); | ||
sw.Reset(); | ||
sw.Start(); | ||
for (int i = 0; i < n_counter; i++) { | ||
STJson.Deserialize<UserInfo>(str_json); | ||
} | ||
sw.Stop(); | ||
Console.WriteLine("STJson : " + sw.ElapsedMilliseconds); | ||
// ==================================================================================================== | ||
System.Threading.Thread.Sleep(5000); | ||
Console.WriteLine("========================================"); | ||
Console.WriteLine("[Serialize] - " + n_counter); | ||
sw.Reset(); | ||
sw.Start(); | ||
for (int i = 0; i < n_counter; i++) { | ||
JsonConvert.SerializeObject(obj_test); | ||
} | ||
sw.Stop(); | ||
Console.WriteLine("Newstonoft : " + sw.ElapsedMilliseconds); | ||
|
||
// sw.Restart(); | ||
// for (int i = 0; i < nCount; i++) { | ||
sw.Reset(); | ||
sw.Start(); | ||
for (int i = 0; i < n_counter; i++) { | ||
STJson.Serialize(obj_test); | ||
} | ||
sw.Stop(); | ||
Console.WriteLine("STJson : " + sw.ElapsedMilliseconds); | ||
|
||
// var aaa = STJson.Deserialize<TestObject>(str); | ||
// } | ||
// sw.Stop(); | ||
// Console.WriteLine(sw.ElapsedMilliseconds); | ||
//} | ||
Console.ReadKey(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.