• 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());
                }
    
            }
        }
    }
    

      

  • 相关阅读:
    关于需求转化的事情
    自由邮件的配置
    广告数据关联CS后台数据
    向新同事学习,如何配置邮件
    渠道映射等关系
    机器学习基本概念
    家政业务系统常识
    SAP APO
    SAP Web Dynpro
    SAP Web Dynpro-监视应用程序
  • 原文地址:https://www.cnblogs.com/sanday/p/7809561.html
Copyright © 2020-2023  润新知