?????????????????????????JsonBuilder???????????·???????汾????δ?????????????????????????????????????????????Ч????????
?????????λ?????Json?????????????????????????????????????????????ο????????????????JsonBuilder?????????
????????????
using System;
using System.Collections.Generic;
/// <summary> ???????
/// </summary>
public class User
{
public static User TestUser()
{//????????????????????????????????????????????????????г????????
User user = new User();
user.UID = Guid.NewGuid();
user.Birthday = new DateTime(1986?? 10?? 29?? 18?? 00?? 00);
user.IsDeleted = false;
user.Name = "blqw";
user.Sex = UserSex.Male;
user.LoginHistory = new List<DateTime>();
user.LoginHistory.Add(DateTime.Today.Add(new TimeSpan(8?? 00?? 00)));
user.LoginHistory.Add(DateTime.Today.Add(new TimeSpan(10?? 10?? 10)));
user.LoginHistory.Add(DateTime.Today.Add(new TimeSpan(12?? 33?? 56)));
user.LoginHistory.Add(DateTime.Today.Add(new TimeSpan(17?? 25?? 18)));
user.LoginHistory.Add(DateTime.Today.Add(new TimeSpan(23?? 06?? 59)));
user.Info = new UserInfo();
user.Info.Address = "?????????";
user.Info.ZipCode = 510000;
user.Info.Phone = new Dictionary<string?? string>();
user.Info.Phone.Add("???"?? "18688888888");
user.Info.Phone.Add("?綽"?? "82580000");
user.Info.Phone.Add("???"?? "10086");
user.Info.Phone.Add("QQ"?? "21979018");
user.Double = Double.NegativeInfinity;
// user.Self = user; //????????????????????????????
return user;
}
public User Self { get; set; }
//User self
/// <summary> ID
/// </summary>
public Guid UID { get; set; }
/// <summary> ???????
/// </summary>
public string Name { get; set; }
/// <summary> ????
/// </summary>
public DateTime Birthday { get; set; }
/// <summary> ???
/// </summary>
public UserSex Sex { get; set; }
/// <summary> ?????????
/// </summary>
public bool IsDeleted { get; set; }
/// <summary> ????????
/// </summary>
public List<DateTime> LoginHistory { get; set; }
/// <summary> ??????
/// </summary>
public UserInfo Info { get; set; }
public Double Double { get; set; }
}
/// <summary> ??????
/// </summary>
public enum UserSex
{
/// <summary> ??
/// </summary>
Male??
/// <summary> ?
/// </summary>
Female
}
/// <summary> ??????
/// </summary>
public class UserInfo
{
/// <summary> ???
/// </summary>
public string Address { get; set; }
/// <summary> ??????
/// </summary>
public Dictionary<string?? string> Phone { get; set; }
/// <summary> ????????
/// </summary>
public int ZipCode { get; set; }
}
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Reflection.Emit;
using System.Data;
using fastJSON;
using System.IO;
using System.Threading;
namespace blqw
{
class Program
{
static void Main(string[] args)
{
int count = 10000;
var obj = User.TestUser();
TestJavaScriptSerializer(count?? obj);
TestNewtonsoftJson(count?? obj);
TestJayrockJson(count?? obj);
TestFastJson(count?? obj);
TestQuickJsonBuilder(count?? obj);
TestJsonBuilder(count?? obj);
}
//????QuickJsonBuilder????
static void TestQuickJsonBuilder(int count?? object obj)
{
Stopwatch sw = new Stopwatch();
Console.WriteLine();
Console.WriteLine("QuickJsonBuilder ???" + count + " ??10??");
for (int j = 0; j < 10; j++)
{
sw.Restart();
for (int i = 0; i < count; i++)
{
QuickJsonBuilder jb = new QuickJsonBuilder();
jb.ToJson(obj);
}
sw.Stop();
Console.Write(sw.ElapsedMilliseconds + "ms | ");
}
Console.WriteLine();
Console.WriteLine("???:" + new QuickJsonBuilder().ToJson(obj));
Console.WriteLine("==============================================");
}