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

        }
    }
}

  

转载于:https://www.cnblogs.com/sanday/p/7809561.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值