zoukankan      html  css  js  c++  java
  • C# Stopwatch计时统计

    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Text;
    using System.Threading;
    
    namespace ConsoleApp1
    {
        class Program
        {
            /// <summary>
            /// Stopwatch计时统计
            /// </summary>
            /// <param name="args"></param>
            static void Main(string[] args)
            {
                var stopwatch = new Stopwatch();//记录时间
                stopwatch.Start();//开始计时
                //实例化类,为线程提供参数
                Demo d1 = new Demo(1, 4);
                Thread th1 = new Thread(new ThreadStart(d1.Start));
                th1.Start();
                Thread.Sleep(1000);
                long sum = 0;
                for(int i=0;i<=1000000;i++)
                {
                    sum = sum + i;
                }
                Thread.Sleep(6000);//休眠6秒
                stopwatch.Stop();//结束计时
                Console.WriteLine("耗时(毫秒):" + stopwatch.ElapsedMilliseconds.ToString());//用时多少毫秒
                Console.WriteLine("sun="+sum);
                Console.ReadLine();
            }
        }
        class Demo
        {
            private int a;
            private int b;
            public Demo(int a, int b)
            {
                this.a = a;
                this.b = b;
            }
            public void Start()
            {
                for (int i = a; i < b; i++)
                {
                    Console.WriteLine(i.ToString());
                }
    
            }
        }
    }
    

      

  • 相关阅读:
    关于区间数颜色的主席树解决
    1020考试总结
    QR算法
    新的征程
    端点星2020.12.2联赛
    自我介绍&友链
    3个搜索
    搜索格式这样写
    T107073 归并排序
    还有这个题
  • 原文地址:https://www.cnblogs.com/sanday/p/7809561.html
Copyright © 2011-2022 走看看