zoukankan      html  css  js  c++  java
  • Parallel Power并行的力量(一个测试代码)

    Parallel
    1. using System;
    2. using System.Collections.Generic;
    3. using System.Diagnostics;
    4. using System.Linq;
    5. using System.Text;
    6. using System.Threading;
    7.  
    8. namespace ConsoleApplication2
    9. {
    10.     class Test
    11.     {
    12.         static void Main()
    13.         {
    14.             int max = 500;
    15.             var query = Enumerable.Range(0, max)
    16.                                   .Select(SlowProjection)
    17.                                   .Where(x => x > 10)
    18.                                   .AsParallel();
    19.             Stopwatch sw = Stopwatch.StartNew();
    20.             int count = query.Count();
    21.             sw.Stop();
    22.             Console.WriteLine("Count: {0} in {1}ms", count,
    23.                               sw.ElapsedMilliseconds);
    24.  
    25.             query = Enumerable.Range(0, max)
    26.                               .AsParallel()
    27.                               .Select(SlowProjection)
    28.                               .Where(x => x > 10);
    29.             sw = Stopwatch.StartNew();
    30.             count = query.Count();
    31.             sw.Stop();
    32.             Console.WriteLine("Count: {0} in {1}ms", count,
    33.                               sw.ElapsedMilliseconds);
    34.             Console.Read();
    35.         }
    36.  
    37.         static int SlowProjection(int input)
    38.         {
    39.             Thread.Sleep(100);
    40.             return input;
    41.         }
    42.     }
    43.  
    44. }

    这里比较了两种使用并行效率的比较,没有写顺序执行的原因你懂的.

  • 相关阅读:
    Jenkins调用selenium找不到webdriver:selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary
    列表的基本操作
    jenkins集成发送测试报告的常见问题解决
    Chrome 浏览器前端调试技巧大揭秘
    搭建Redis三主三从集群
    Jenkins安装
    python中hasattr()、getattr()、setattr()函数的使用
    python单元测试之unittest框架
    python环境配置详细步骤
    Android:EditText 设置弹出数字输入法键盘
  • 原文地址:https://www.cnblogs.com/jinzhao/p/2159753.html
Copyright © 2011-2022 走看看