Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: animaonline on Jan 27th, 2014  |  syntax: C#  |  size: 0.67 KB  |  views: 59  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.         {
  2.             IEnumerable<string> queryResults;
  3.             bool useParallel = true;
  4.  
  5.             var strings = new List<string>();
  6.  
  7.             for (int i = 0; i < 2500000; i++)
  8.                 strings.Add(i.ToString());
  9.  
  10.             var stp = new Stopwatch();
  11.  
  12.             stp.Start();
  13.  
  14.             if (useParallel)
  15.                 queryResults = strings.AsParallel().Where(item => item.Contains("1")).ToList();
  16.             else
  17.                 queryResults = strings.Where(item => item.Contains("1")).ToList();
  18.  
  19.             stp.Stop();
  20.  
  21.             Console.WriteLine("useParallel: {0}\r\nTime Elapsed: {1}", useParallel, stp.ElapsedMilliseconds);
  22.         }
clone this paste RAW Paste Data