T GenerateTestData2 <T, U>(GenerateFunc <U> generateValue) where T : new() { T data = new T(); typeof(T).GetField("value").SetValue(data, generateValue()); return(data); }
ArrayClass <T> GenerateTestData2 <T>(int count, GenerateFunc <T> generate) { ArrayClass <T> data = new ArrayClass <T>(); data.array = new T[count]; for (int i = 0; i < count; ++i) { data.array[i] = generate(); } return(data); }
void Test1 <T, U>(string name, GenerateFunc <U> generate) where T : new() { resultText = new StringBuilder(); T obj = GenerateTestData2 <T, U>(generate); Stopwatch("FastJson,s," + name, () => { FastJson.Serialize(obj); }); //Stopwatch( "EasyJson,s,"+name, ()=>{ EasyJSON.Serializer.Serialize(obj); } ); //Stopwatch( "XML-JSON,s,"+name, ()=>{ JSONSerializer.Serialize(obj); } ); //Stopwatch( "JSON.NET,s,"+name, ()=>{ Newtonsoft.Json.JsonConvert.SerializeObject(obj); } ); string fastJsonText = FastJson.Serialize(obj); //string jsonDotNetText = Newtonsoft.Json.JsonConvert.SerializeObject(obj); //string easyJsonText = EasyJSON.Serializer.Serialize(obj); //string xmlJsonText = JSONSerializer.Serialize(obj); Stopwatch("FastJson,d," + name, () => { FastJson.Deserialize <T>(fastJsonText); }); //Stopwatch( "EasyJson,d,"+name, ()=>{ EasyJSON.Serializer.Deserialize<T>(easyJsonText); } ); //Stopwatch( "XML-JSON,d,"+name, ()=>{ JSONSerializer.Deserialize<T>(xmlJsonText); } ); //Stopwatch( "JSON.NET,d,"+name, ()=>{ Newtonsoft.Json.JsonConvert.DeserializeObject<T>(jsonDotNetText); } ); Debug.Log(resultText.ToString()); }
public static Dictionary <char, int> GenerateNewInstance() => GenerateFunc()();
static AlphabetDictionaryGenerator() { AlphabetCache = GenerateFunc()(); }