zoukankan      html  css  js  c++  java
  • C# 计时程序运行时间

    第一种   System.DateTime

    public static void SubTest()
            {
                DateTime beforeDT = System.DateTime.Now;
                int[] a = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
                //Shuffle(a) is the function you want to test.
                Shuffle(a);
                DateTime afterDT = System.DateTime.Now;
                TimeSpan ts = afterDT.Subtract(beforeDT);
                Console.WriteLine("DateTime costed for Shuffle function is: {0}ms",ts.TotalMilliseconds);
            }

    第二种用Stopwatch类(System.Diagnostics)

     /// <summary>
            /// 测试for循环优化
            /// </summary>
            /// <returns></returns>
            [HttpGet("test")]
            public ActionResult<ApiResponse> test()
            {
                var result = new ApiResponse();
               Stopwatch sw = new Stopwatch();
               sw.Start();
               //耗时程序
    
                sw.Stop();
                TimeSpan ts = sw.Elapsed;
                Console.WriteLine("DateTime costed for Shuffle function is: {0}ms", ts.TotalMilliseconds);
                return result;
    
            }

     转自:https://www.cnblogs.com/I-am-Betty/p/10489787.html

  • 相关阅读:
    sql
    po bo vo java bean
    jdk面试
    Bean 参数时间 设置
    kafka demo
    spring注解 动态修改注解的值
    参考资料
    Centos 编译带调试信息的libevent
    mysql 库表整体相关查询
    MySQL安装(linux)
  • 原文地址:https://www.cnblogs.com/xuqp/p/11756736.html
Copyright © 2011-2022 走看看