public static void RunCsvListTest() { //ShiboSerializer.Serialize(os, graph, sets); //List<int> v = new List<int>(); //v.Add(123); //v.Add(456); //IList<bool> v = new List<bool>(); //v.Add(true); //v.Add(false); int n = 100; IList <Int32Class> v = new List <Int32Class>(n); for (int i = 0; i < n; i++) { v.Add(ShiboSerializer.Initialize <Int32Class>()); } string csv = ShiboSerializer.ToCsv(v); //CsvHelper.CsvWriter c = new CsvHelper.CsvWriter(); Console.WriteLine(csv); }
public static void TestCase6() { TestBaseConfig.Seed = 1; StringListClass a = ShiboSerializer.Initialize <StringListClass>(123456); //a.V1 = new uint[]{}; StringListClass c = null; string json = ShiboSerializer.Serialize(a); c = ShiboSerializer.Deserialize <StringListClass>(json); c = JsonConvert.DeserializeObject <StringListClass>(json); //byte[] bytes = ShiboSerializer.BinSerialize(a); Console.WriteLine(JsonConvert.SerializeObject(a) == json); //Test(a); Stopwatch w = Stopwatch.StartNew(); for (int i = 0; i < 100000; i++) { //json = JsonConvert.SerializeObject(a); //json = ShiboSerializer.Serialize(a); c = ShiboSerializer.Deserialize <StringListClass>(json); //c = JsonConvert.DeserializeObject<StringListClass>(json); //c = ShiboSerializer.BinDeserialize<Int32ArrayClass>(bytes); } w.Stop(); Console.WriteLine(w.ElapsedMilliseconds); Console.WriteLine(JsonConvert.SerializeObject(a) == JsonConvert.SerializeObject(c)); }
public static void TestCase7() { string path = "bigjson.txt"; if (File.Exists(path)) { TestBaseConfig.Seed = 1; string json = File.ReadAllText(path); ClubJsonCase o = ShiboSerializer.Initialize <ClubJsonCase>();// ShiboSerializer.Deserialize<ClubJsonCase>(json); //ClubJsonCase o1 = JsonConvert.DeserializeObject<ClubJsonCase>(json); json = JsonConvert.SerializeObject(o); //Console.WriteLine(JsonConvert.SerializeObject(o) == JsonConvert.SerializeObject(o1)); ClubJsonCase o1 = null; o1 = ShiboSerializer.Deserialize <ClubJsonCase>(json); o1 = JsonConvert.DeserializeObject <ClubJsonCase>(json); //Result o2 = null; Stopwatch w = Stopwatch.StartNew(); for (int i = 0; i < 100; i++) { //o1 = ShiboSerializer.Deserialize<ClubJsonCase>(json); //o1 = JsonConvert.DeserializeObject<ClubJsonCase>(json); //o2 = ShiboSerializer.Deserialize<Result>(json); //o2 = JsonConvert.DeserializeObject<Result>(json); } w.Stop(); Console.WriteLine(w.ElapsedMilliseconds); Console.WriteLine(JsonConvert.SerializeObject(o) == JsonConvert.SerializeObject(o1)); //Console.WriteLine(JsonConvert.SerializeObject(o1.Result) == JsonConvert.SerializeObject(o2)); } }
public static void TestCase14() { TestBaseConfig.Seed = 1; Int32Class a = ShiboSerializer.Initialize <Int32Class>(53456158); byte[] bytes = ShiboSerializer.BinarySerialize(a); Int32Class b = ShiboSerializer.BinaryDeserialize <Int32Class>(bytes); //Console.WriteLine(ShiboComparer.Compare<List<string>>(a, b)); Console.WriteLine(JsonConvert.SerializeObject(a) == JsonConvert.SerializeObject(b)); ObjectWriter bf = new ObjectWriter(50); Stopwatch w = Stopwatch.StartNew(); for (int i = 0; i < 1000000; i++) { //bytes = ShiboSerializer.BinarySerialize(a); //b = ShiboSerializer.BinaryDeserialize<List<string>>(bytes); bf.Reset(); ShiboSerializer.BinarySerialize(bf, a); } w.Stop(); Console.WriteLine(w.ElapsedMilliseconds); //Console.WriteLine(JsonConvert.SerializeObject(b.Count)); }
public static void TestCase1() { //Guid guid = new Guid("e92b8e30-a6e5-41f6-a6b9-188230a23dd2"); //byte[] buffer = guid.ToByteArray(); //Console.WriteLine(BitConverter.ToString(buffer)); Dictionary <int, string> v = new Dictionary <int, string>(); v.Add(1, null); TestBaseConfig.Seed = 1; Int32Class a = ShiboSerializer.Initialize <Int32Class>();// Int32Class.Init(); string s1 = ShiboSerializer.Serialize(a); string s2 = null; byte[] buffer = ShiboSerializer.BinarySerialize(a); a = ShiboSerializer.BinaryDeserialize <Int32Class>(buffer); s2 = ShiboSerializer.Serialize(a); Console.WriteLine(BitConverter.ToString(buffer)); Console.WriteLine(s1 == s2); //Console.ReadLine(); Test(a); //Int32FieldClass a = Int32FieldClass.Init(); //byte[] buffer = ShiboSerializer.BinSerialize(a); ////byte[] b = new byte[400]; ////Buffer.BlockCopy(buffer, 0, b, 0, 4); //a = ShiboSerializer.BinDeserialize<Int32FieldClass>(buffer); //Console.WriteLine(BitConverter.ToString(buffer)); //Console.WriteLine(ShiboSerializer.Serialize(a)); Console.ReadLine(); }
public void Setup() { data = new Int32Class[Size]; for (int i = 0; i < data.Length; i++) { data[i] = ShiboSerializer.Initialize <Int32Class>(); } }
public void TestAllBaseType() { var data = new TestAllBaseType[100]; for (int i = 0; i < data.Length; i++) { data[i] = ShiboSerializer.Initialize <TestAllBaseType>(); } var ret = ShiboSerializer.ToColumns(data); var boolValue = new bool[data.Length]; var boolValueFalse = new bool[data.Length]; var byteValue = new byte[data.Length]; var sbyteValue = new sbyte[data.Length]; var charValue = new char[data.Length]; var shortValue = new short[data.Length]; var ushortValue = new ushort[data.Length]; var intValue = new int[data.Length]; var uintValue = new uint[data.Length]; var longValue = new long[data.Length]; var ulongValue = new ulong[data.Length]; var floatValue = new float[data.Length]; var doubleValue = new double[data.Length]; var decimalValue = new decimal[data.Length]; for (int i = 0; i < data.Length; i++) { boolValue[i] = data[i].boolValue; boolValueFalse[i] = data[i].boolValueFalse; byteValue[i] = data[i].byteValue; sbyteValue[i] = data[i].sbyteValue; charValue[i] = data[i].charValue; shortValue[i] = data[i].shortValue; ushortValue[i] = data[i].ushortValue; intValue[i] = data[i].intValue; uintValue[i] = data[i].uintValue; longValue[i] = data[i].longValue; ulongValue[i] = data[i].ulongValue; floatValue[i] = data[i].floatValue; doubleValue[i] = data[i].doubleValue; decimalValue[i] = data[i].decimalValue; } Assert.AreEqual(Json(ret[0].Value), Json(boolValue)); Assert.AreEqual(Json(ret[1].Value), Json(boolValueFalse)); Assert.AreEqual(Json(ret[2].Value), Json(byteValue)); Assert.AreEqual(Json(ret[3].Value), Json(sbyteValue)); Assert.AreEqual(Json(ret[4].Value), Json(charValue)); Assert.AreEqual(Json(ret[5].Value), Json(shortValue)); Assert.AreEqual(Json(ret[6].Value), Json(ushortValue)); Assert.AreEqual(Json(ret[7].Value), Json(intValue)); Assert.AreEqual(Json(ret[8].Value), Json(uintValue)); Assert.AreEqual(Json(ret[9].Value), Json(longValue)); Assert.AreEqual(Json(ret[10].Value), Json(ulongValue)); Assert.AreEqual(Json(ret[11].Value), Json(floatValue)); Assert.AreEqual(Json(ret[12].Value), Json(doubleValue)); Assert.AreEqual(Json(ret[13].Value), Json(decimalValue)); }
public static void MultipleTypeMethodTest() { PrimitiveTypeClass v = ShiboSerializer.Initialize <PrimitiveTypeClass>(4578424); string json = ShiboSerializer.Serialize(v); byte[] bytes = ShiboSerializer.BinarySerialize(v); Console.WriteLine(json == JsonConvert.SerializeObject(v)); v = ShiboSerializer.BinaryDeserialize <PrimitiveTypeClass>(bytes); Console.WriteLine(json == JsonConvert.SerializeObject(v)); }
public static void TestCase8() { TestBaseConfig.Seed = 1; MixClass a = ShiboSerializer.Initialize <MixClass>(TestBaseConfig.Seed); //a.V8 = "sdfdfg"; //a.V5.V3 = 1; MixClass b = ShiboSerializer.Initialize <MixClass>(TestBaseConfig.Seed); //b.V8 = "sdfdfg"; //Assert.AreEqual( //Console.WriteLine(ShiboComparer.Compare(a, b)); }
public void Setup() { dataInt8 = new Int8Class[Size]; dataInt32 = new Int32Class[Size]; dataInt64 = new Int64Class[Size]; for (int i = 0; i < dataInt8.Length; i++) { dataInt8[i] = ShiboSerializer.Initialize <Int8Class>(); dataInt32[i] = ShiboSerializer.Initialize <Int32Class>(); dataInt64[i] = ShiboSerializer.Initialize <Int64Class>(); } }
public void TestInt32Bytes() { var data = new Int32Class[10]; for (int i = 0; i < data.Length; i++) { data[i] = ShiboSerializer.Initialize <Int32Class>(); } var expected = ServiceStack.Text.CsvSerializer.SerializeToCsv(data); var actual = Encoding.UTF8.GetString(ShiboSerializer.ToCsvUtf8(data)); Assert.AreEqual(expected, actual); }
public void TestInt8() { var data = new Int8Class[100]; for (int i = 0; i < data.Length; i++) { data[i] = ShiboSerializer.Initialize <Int8Class>(); } var expected = ServiceStack.Text.CsvSerializer.SerializeToCsv(data); var actual = ShiboSerializer.ToCsv(data); Assert.AreEqual(expected, actual); }
/// <summary> /// 对象数据初始化测试 /// </summary> public static void TestCase7() { TestBaseConfig.Seed = 1; MixClass a = ShiboSerializer.Initialize <MixClass>(); Stopwatch w = Stopwatch.StartNew(); for (int i = 0; i < 1000000; i++) { a = ShiboSerializer.Initialize <MixClass>(); } w.Stop(); Console.WriteLine(w.ElapsedMilliseconds); Console.WriteLine(JsonConvert.SerializeObject(a)); }
public MixClass(int seed) { rd = new Random(seed); //V0 = (byte)rd.Next(int.MinValue, int.MaxValue); //V1 = (sbyte)rd.Next(int.MinValue, int.MaxValue); //V2 = (short)rd.Next(int.MinValue, int.MaxValue); //V3 = (ushort)rd.Next(int.MinValue, int.MaxValue); V4 = rd.Next(int.MinValue, int.MaxValue); V5 = ShiboSerializer.Initialize <Int32Class>(); //Int32Class.Init(); //V6 = new int[rd.Next(TestBaseConfig.ArrayMinSize, TestBaseConfig.ArrayMaxSize)]; //for (int i = 0; i < V6.Length; i++) // V6[i] = (int)rd.Next(sbyte.MinValue, sbyte.MaxValue); V7 = rd.Next(int.MinValue, int.MaxValue); }
public static void Run() { var Size = 10; var data = new Int8Class[Size]; for (int i = 0; i < data.Length; i++) { data[i] = ShiboSerializer.Initialize <Int8Class>(); } var result = ConvertInt8Class(data); var str = Encoding.UTF8.GetString(result); Console.WriteLine(result); }
public static void TestCase2() { TestBaseConfig.Seed = 1; Int32Class a = ShiboSerializer.Initialize <Int32Class>(); //Int32Class.Init(); byte[] buffer = ShiboSerializer.BinarySerialize(a); Int32Class b = ShiboSerializer.BinaryDeserialize <Int32Class>(buffer); Stopwatch w = Stopwatch.StartNew(); for (int i = 0; i < 1000000; i++) { buffer = ShiboSerializer.BinarySerialize(a); //b = ShiboSerializer.BinDeserialize<Int32Class>(buffer); } w.Stop(); Console.WriteLine(w.ElapsedMilliseconds); Console.WriteLine(JsonConvert.SerializeObject(a) == JsonConvert.SerializeObject(b)); }
/// <summary> /// /// </summary> public static void TestCase10() { TestBaseConfig.Seed = 1; Dictionary <int, bool> a = ShiboSerializer.Initialize <Dictionary <int, bool> >(53456158); byte[] bytes = ShiboSerializer.BinarySerialize(a); Dictionary <int, bool> b = ShiboSerializer.BinaryDeserialize <Dictionary <int, bool> >(bytes); Stopwatch w = Stopwatch.StartNew(); for (int i = 0; i < 10000; i++) { //bytes = ShiboSerializer.BinarySerialize(a); b = ShiboSerializer.BinaryDeserialize <Dictionary <int, bool> >(bytes); } w.Stop(); Console.WriteLine(w.ElapsedMilliseconds); Console.WriteLine(JsonConvert.SerializeObject(b.Count)); }
public static void TestCase13() { TestBaseConfig.Seed = 1; byte[][] a = ShiboSerializer.Initialize <byte[][]>(53456158); byte[] bytes = ShiboSerializer.BinarySerialize(a); byte[][] b = ShiboSerializer.BinaryDeserialize <byte[][]>(bytes); //Console.WriteLine(ShiboComparer.Compare<List<string>>(a, b)); Console.WriteLine(JsonConvert.SerializeObject(a) == JsonConvert.SerializeObject(b)); //Stopwatch w = Stopwatch.StartNew(); //for (int i = 0; i < 10000; i++) //{ // //bytes = ShiboSerializer.BinarySerialize(a); // b = ShiboSerializer.BinaryDeserialize<List<string>>(bytes); //} //w.Stop(); //Console.WriteLine(w.ElapsedMilliseconds); //Console.WriteLine(JsonConvert.SerializeObject(b.Count)); }
public void TestInt64() { var data = new Int64Class[100]; for (int i = 0; i < data.Length; i++) { data[i] = ShiboSerializer.Initialize <Int64Class>(); } var ret = ShiboSerializer.ToColumns(data); var v0s = new long[data.Length]; for (int i = 0; i < data.Length; i++) { v0s[i] = data[i].V0; } var v1 = Csv((long[])ret[0].Value); var v2 = Csv(v0s); Assert.AreEqual(v1, v2); }
public void TestInt8() { var data = new Int8Class[100]; for (int i = 0; i < data.Length; i++) { data[i] = ShiboSerializer.Initialize <Int8Class>(); } var ret = ShiboSerializer.ToColumns(data); var bytes = new byte[data.Length]; for (int i = 0; i < data.Length; i++) { bytes[i] = data[i].V0; } var v1 = ServiceStack.Text.CsvSerializer.SerializeToCsv((byte[])ret[0].Value); var v2 = ServiceStack.Text.CsvSerializer.SerializeToCsv(bytes); Assert.AreEqual(v1, v2); }
public void TestInt32() { var data = new Int32Class[100]; for (int i = 0; i < data.Length; i++) { data[i] = ShiboSerializer.Initialize <Int32Class>(); } var ret = ShiboSerializer.ToColumns(data); var bytes = new int[data.Length]; for (int i = 0; i < data.Length; i++) { bytes[i] = data[i].V0; } var v1 = Csv((int[])ret[0].Value); var v2 = Csv(bytes); Assert.AreEqual(v1, v2); }
public void Setup() { dataInt8 = new Int8Class[Size]; for (int i = 0; i < Size; i++) { dataInt8[i] = ShiboSerializer.Initialize <Int8Class>(); } buffer = new byte[10][]; for (int j = 0; j < buffer.Length; j++) { buffer[j] = new byte[dataInt8.Length]; } v0 = new byte[dataInt8.Length]; v1 = new byte[dataInt8.Length]; v2 = new byte[dataInt8.Length]; v3 = new byte[dataInt8.Length]; v4 = new byte[dataInt8.Length]; v5 = new byte[dataInt8.Length]; v6 = new byte[dataInt8.Length]; v7 = new byte[dataInt8.Length]; v8 = new byte[dataInt8.Length]; v9 = new byte[dataInt8.Length]; }
public static void TestCase3() { TestBaseConfig.Seed = 1; Int32Class a = ShiboSerializer.Initialize <Int32Class>(); //Int32Class.Init(); string json = ShiboSerializer.Serialize(a); Int32Class b = ShiboSerializer.Deserialize <Int32Class>(json); b = JsonConvert.DeserializeObject <Int32Class>(json); //Test(a); Stopwatch w = Stopwatch.StartNew(); for (int i = 0; i < 1000000; i++) { //json = JsonConvert.SerializeObject(a); //json = ShiboSerializer.Serialize(a); ShiboSerializer.SerializeToBuffer(a); //b = ShiboSerializer.Deserialize<Int32Class>(json); //b = JsonConvert.DeserializeObject<Int32Class>(json); } w.Stop(); Console.WriteLine(w.ElapsedMilliseconds); Console.WriteLine(JsonConvert.SerializeObject(a) == JsonConvert.SerializeObject(b)); }