Esempio n. 1
0
        private static void TestDtoMapper()
        {
            //比较TinyMapper和EmitMapper的性能
            var input = new DtoFrom
            {
                Name        = "zhangsan",
                Age         = 20,
                CreatedTime = DateTime.Now
            };
            DtoTo result    = null;
            var   iteration = 10 * 10000;

            CodeTimerHelper.Initialize();

            //1,EmitMapper
            CodeTimerHelper.Time("EmitMapper性能测试(10 * 10000)", iteration, () =>
            {
                var mapper = ObjectMapperManager.DefaultInstance.GetMapper <DtoFrom, DtoTo>();
                result     = mapper.Map(input);
            });

            //2,TinyMapper
            CodeTimerHelper.Time("TinyMapper性能测试(10 * 10000)", iteration, () =>
            {
                TinyMapper.Bind <DtoFrom, DtoTo>();
                result = TinyMapper.Map <DtoTo>(input);
            });

            Console.ReadKey();
        }
Esempio n. 2
0
 static void TestFib()
 {
     CodeTimerHelper.Time("Fib", 1, () => {
         //var a = new DynamicPlan().Fib(40);
         //var a = TestFib(40);
         var a = new DynamicPlan().Fib3(40);
         Console.WriteLine(a);
     });
 }
Esempio n. 3
0
        private static void Main(string[] args)
        {
            var userInfo = new { Name = "Kt" };

            if (userInfo == null)
            {
                throw new Exception("Object Is Null");
            }
            PropertyInfo[] Properties = userInfo.GetType().GetProperties();
            string         xml        = "<xml>";

            foreach (PropertyInfo p in Properties)
            {
                string str = p.Name + " = " + p.GetValue(userInfo, null);
            }
            Console.ReadKey();

            var          sqlConn = @"Data Source=.;Initial Catalog=test;User Id=sa;Password=123456;";
            var          sqlCmd  = "Select count(1) From [Test].[dbo].[UserInfo] Where [Id] >= @Id ";
            SqlParameter sp      = new SqlParameter("@Id", SqlDbType.Int);

            sp.Value = 0;
            Object obj   = SqlHelper.ExecuteScalar(sqlConn, CommandType.Text, sqlCmd, sp);
            var    count = FunHelper.GetValue(obj, 0);

            sqlCmd = "Select * From [Test].[dbo].[UserInfo] Where [Id] >= @Id ";
            DataSet   ds = SqlHelper.ExecuteDataset(sqlConn, CommandType.Text, sqlCmd, sp);
            DataTable dt = (ds.Tables != null && ds.Tables.Count > 0) ? ds.Tables[0] : null;

            if (dt != null && dt.Rows.Count > 0)
            {
                var user = new { Name = (string)dt.Rows[0]["Name"] };   // DataTable To List
            }
            sqlCmd = " Update [Test].[dbo].[UserInfo]  Set [Name]='Updated' Where [Id] = @Id ";
            var updated = SqlHelper.ExecuteNonQuery(sqlConn, CommandType.Text, sqlCmd, sp) >= 1;

            sqlCmd = "if exists( Select count(1) From [Test].[dbo].[UserInfo] Where [Id] >= @Id  ) begin select '1' end ; else begin select '0' end ;";
            var exists = FunHelper.GetValue(SqlHelper.ExecuteScalar(sqlConn, CommandType.Text, sqlCmd, sp), 0) >= 1;

            Console.ReadKey();

            var html = HttpHelper.HttpGet("http://china.huanqiu.com/article/2016-01/8461794.html?from=bdwz", "utf-8", "text/html");
            var res  = StringHelper.RemoveHTML(html);

            var html1 = HttpHelper.HttpGet("http://www.caogen.com/blog/Infor_detail/77018.html", "GB2312", "text/html");
            var res1  = StringHelper.RemoveHTML(html1);

            CodeTimerHelper.Time("性能测试", 1000, () =>
            {
                StringHelper.RemoveHTML(html1);
            });
            Console.ReadKey();
        }
Esempio n. 4
0
        /// <summary>
        /// dapper批量插入测试demo
        /// </summary>
        private static void TestBatchInsertDemo()
        {
            //比较dapper的insert into values和SqlBulkCopy的性能
            //测试情形1:insert into单条插入100000条
            //测试情形2:insert into多条插入100000条,100*1000
            //测试情形3:SqlBulkCopy批量插入,100*1000
            var connStr = "Data Source=.;Initial Catalog=TestDB;Persist Security Info=True;User ID=sa;Password=password.123";

            //1
            var item = new TestBatchInsert {
                Val = Guid.NewGuid().ToString()
            };

            CodeTimerHelper.Initialize();
            CodeTimerHelper.Time("dapper单条插入", 10000, () =>
            {
                new SqlHelper(connStr).Execute(@"INSERT INTO dbo.TestBatchInsert VALUES (@Val);", item);
            });

            List <TestBatchInsert> list = new List <TestBatchInsert>();
            var nums = Enumerable.Range(0, 100).ToList();

            nums.ForEach(i =>
            {
                list.Add(new TestBatchInsert
                {
                    Val = Guid.NewGuid().ToString()
                });
            });
            //2
            CodeTimerHelper.Time("dapper批量插入", 100, () =>
            {
                new SqlHelper(connStr).Execute(@"INSERT INTO dbo.TestBatchInsert VALUES (@Val);", list);
            });

            //3
            List <TestBatchInsert> list2 = new List <TestBatchInsert>();

            nums.ForEach(i =>
            {
                list2.Add(new TestBatchInsert
                {
                    Val = Guid.NewGuid().ToString()
                });
            });
            CodeTimerHelper.Time("SqlBulkCopy批量插入", 100, () =>
            {
                new SqlHelper(connStr).BulkCopy(list2, "TestBatchInsert");
            });

            Console.ReadKey();
        }
Esempio n. 5
0
        private static void Main_CodeTimerHelper(string[] args)
        {
            int arraySize;

            int[]  data;
            Random rnd;

            arraySize = 10000;
            data      = new int[arraySize];

            rnd = new Random(0);
            for (int c = 0; c < arraySize; ++c)
            {
                data[c] = rnd.Next(256);
            }

            long sum = 0;

            CodeTimerHelper.Time("unsorted array", 100000, () =>
            {
                for (int c = 0; c < arraySize; ++c)
                {
                    if (data[c] >= 128)
                    {
                        sum += data[c];
                    }
                }
            });

            Array.Sort(data);

            sum = 0;
            CodeTimerHelper.Time("sorted array", 100000, () =>
            {
                for (int c = 0; c < arraySize; ++c)
                {
                    if (data[c] >= 128)
                    {
                        sum += data[c];
                    }
                }
            });
        }
Esempio n. 6
0
        /// <summary>
        /// 测试深克隆的性能
        /// </summary>
        private static void TestDeepClonePerf()
        {
            var iteration = 10 * 10000;

            CodeTimerHelper.Initialize();

            var input = new DtoFrom
            {
                Name        = "aaa",
                Age         = 100,
                CreatedTime = DateTime.Now
            };

            DtoFrom result = null;

            CodeTimerHelper.Time("测试深克隆的性能", iteration, () =>
            {
                result = input.DeepClone();
            });
            Console.ReadKey();
        }