示例#1
0
        private static void testEntityList()
        {
            try {
                LightweightTextSerializer ser = new LightweightTextSerializer();

                ArrayList lstData = new ArrayList();

                for (int i = 0; i < 10000; i++)
                {
                    MyProduct p = new MyProduct();
                    p.ID         = i;
                    p.Name       = "中国" + i;
                    p.Code       = "AAA" + i;
                    p.CreateDate = System.DateTime.Now;
                    p.Count      = 100;
                    lstData.Add(p);
                }

                //DateTime begin = System.DateTime.Now;
                //byte[] soapSer = MB.Util.Serializer.SoapSerializer.DefaultInstance.SerializerToByte(lstData);
                //DateTime end = System.DateTime.Now;
                //TimeSpan span = end.Subtract(begin);
                //Console.WriteLine(string.Format("SOAP 总共转换{0}个对象,转换后的Bytes数为{1},花费时间为{2}", lstData.Count, soapSer.Length, span.TotalMilliseconds));


                //  begin = System.DateTime.Now;
                //MB.Util.Serializer.EntityXmlSerializer<MyProduct> xmS = new MB.Util.Serializer.EntityXmlSerializer<MyProduct>();
                //string ss = xmS.Serializer(products);
                //byte[] xmlBytes = (new ASCIIEncoding()).GetBytes(ss);
                //  end = System.DateTime.Now;
                //  span = end.Subtract(begin);
                //  Console.WriteLine(string.Format("XML 总共转换{0}个对象,转换后的Bytes数为{1},花费时间为{2}", lstData.Count, xmlBytes.Length, span.TotalMilliseconds));


                DateTime begin = System.DateTime.Now;
                byte[]   bytes = ser.Serializer(typeof(MyProduct), lstData);
                DateTime end   = System.DateTime.Now;
                TimeSpan span  = end.Subtract(begin);
                Console.WriteLine(string.Format("总共转换{0}个对象,转换后的Bytes数为{1},花费时间为{2}", lstData.Count, bytes.Length, span.TotalMilliseconds));
                //  Console.ReadLine();
                //begin = System.DateTime.Now;
                //IList rLst = ser.DeSerializer(typeof(MyProduct), bytes);
                //end = System.DateTime.Now;
                //span = end.Subtract(begin);

                //Console.WriteLine(string.Format("转换Bytes数为长度{0},形成{1}个对象,花费时间为{2}", bytes.Length, rLst.Count, span.TotalMilliseconds));

                begin = System.DateTime.Now;
                IList rLstM = ser.DeSerializer(typeof(MyProductEX), bytes);
                end  = System.DateTime.Now;
                span = end.Subtract(begin);

                Console.WriteLine(string.Format("多线程 转换Bytes数为长度{0},形成{1}个对象,花费时间为{2}", bytes.Length, rLstM.Count, span.TotalMilliseconds));

                Console.WriteLine("OK!");
            }
            catch (Exception ex) {
                Console.WriteLine("出错!" + ex.Message);
            }
        }
示例#2
0
        private static void testTable()
        {
            try {
                LightweightTextSerializer ser = new LightweightTextSerializer();

                DataTable dtTable = createTable();

                decimal count = 1000;
                for (int i = 0; i < 10000; i++)
                {
                    DataRow dr = dtTable.NewRow();
                    dr["ID"]         = i;
                    dr["Name"]       = "中国" + i;
                    dr["Code"]       = "AAA" + i;
                    dr["CreateDate"] = DateTime.Now.ToString("yyyy*MM*dd HH:mm");
                    dr["Count"]      = count.ToString("$#,###.00");
                    dtTable.Rows.Add(dr);
                }



                DateTime begin = System.DateTime.Now;
                byte[]   bytes = ser.Serializer(dtTable);
                DateTime end   = System.DateTime.Now;
                TimeSpan span  = end.Subtract(begin);
                Console.WriteLine(string.Format("总共转换{0}个对象,转换后的Bytes数为{1},花费时间为{2}", dtTable.Rows.Count, bytes.Length, span.TotalMilliseconds));

                //BinaryFormatter formatter = new BinaryFormatter();
                //using (MemoryStream tstream = new MemoryStream()) {
                //    formatter.Serialize(tstream, dtTable);
                //    byte[] bytes_c = MB.Util.Compression.Instance.Zip(tstream.ToArray());
                //    Console.WriteLine(string.Format("总共转换{0}个对象,转换后的Bytes数为{1},花费时间为{2}", dtTable.Rows.Count, bytes_c.Length, span.TotalMilliseconds));
                //}


                begin = System.DateTime.Now;
                DataTable rLstM = ser.DeSerializer(bytes);
                end  = System.DateTime.Now;
                span = end.Subtract(begin);

                Console.WriteLine(string.Format("多线程 转换Bytes数为长度{0},形成{1}个对象,花费时间为{2}", bytes.Length, rLstM.Rows.Count, span.TotalMilliseconds));

                Console.WriteLine("OK!");
            }
            catch (Exception ex) {
                Console.WriteLine("出错!" + ex.Message);
            }
        }
示例#3
0
        private static void testDataSet()
        {
            DataTable     dtTable = createTable();
            StringBuilder sb      = new StringBuilder();

            decimal count = 1000;

            for (int i = 0; i < 100000; i++)
            {
                DataRow dr = dtTable.NewRow();
                dr["ID"]         = i;
                dr["Name"]       = "中国" + i;
                dr["Code"]       = "AAA" + i;
                dr["CreateDate"] = DateTime.Now;
                dr["Count"]      = count.ToString("#,###.00");
                dtTable.Rows.Add(dr);

                object[] vals = dr.ItemArray;
                foreach (object v in vals)
                {
                    sb.Append(v);
                    sb.Append("\t");
                }
                sb.Append("\n");
            }
            BinaryFormatter formatter = new BinaryFormatter();

            using (MemoryStream tstream = new MemoryStream()) {
                formatter.Serialize(tstream, dtTable);
                Console.WriteLine("T:" + tstream.ToArray().Length);
            }
            using (MemoryStream tstream = new MemoryStream()) {
                formatter.Serialize(tstream, sb.ToString());
                Console.WriteLine("S:" + tstream.ToArray().Length);
            }
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("zh-CN", false);

            LightweightTextSerializer ser = new LightweightTextSerializer(new ASCIIEncoding());

            byte[] bs = ser.Serializer(dtTable);
            Console.WriteLine("L:" + bs.Length);

            DataTable rLstM = ser.DeSerializer(bs);
        }