Advertisement
NPSF3000

Threaded i++ bilion

May 31st, 2011
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Diagnostics;
  6. using System.Threading.Tasks;
  7.  
  8. namespace simple_performance_test
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. Stopwatch clock = new Stopwatch();
  15. while (true)
  16. {
  17. Console.WriteLine("");
  18. Console.WriteLine("Starting Test");
  19.  
  20. clock.Restart();
  21. int sum = 0;
  22. //for (; sum < 1000000000; sum++) ;
  23.  
  24. int work = 1000000000 / Environment.ProcessorCount;
  25.  
  26. Parallel.For(0, Environment.ProcessorCount, (x) =>
  27. {
  28. int i = 0;
  29. for (; i < work; i++) ;
  30. sum += i;
  31. }
  32. );
  33. clock.Stop();
  34.  
  35. Console.WriteLine("Took " + clock.ElapsedMilliseconds + " to iterate to " + sum);
  36. Console.ReadKey();
  37. }
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement