• Stopwatch运行时间 Parallel并行任务


    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Linq.Expressions;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    
    namespace ConsoleApp2
    {
        class Program
        {
    
            static void Main(string[] args)
            {
                //Stopwatch用于记录代码运行时间
                Stopwatch watch1 = new Stopwatch();
                watch1.Start();
                for (int i = 1; i <= 10; i++)
                {
                    Console.WriteLine(i );
                    Thread.Sleep(1000);
                }
                watch1.Stop();
                Console.WriteLine(watch1.Elapsed);
    
                Stopwatch watch2 = new Stopwatch();
                watch2.Start();
    
                //会调用线程池中的线程
                Parallel.For(1, 11, i =>
                {
                    Console.WriteLine(i + ",线程ID:" + Thread.CurrentThread.ManagedThreadId);
                    //Thread.Sleep(1000);
                });
                watch2.Stop();
                Console.WriteLine(watch2.Elapsed);
            }
    
          
    
        }
    
    
    }
  • 相关阅读:
    python操作excel表格
    重学Java
    重学Java
    重学Java
    重学Java
    重学Java
    博客园自定义主题及目录组件
    重学Java
    修改 Eclipse 背景颜色的高级方法
    dbf转excel
  • 原文地址:https://www.cnblogs.com/chenyishi/p/8334189.html
Copyright © 2020-2023  润新知