Guest User

Untitled

a guest
Nov 21st, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. const int TEST_AMOUNT = 1;
  2.  
  3. var arr = new int[TEST_AMOUNT];
  4. for (int i = 0; i < arr.Length; i++) arr[i] = i + 1;
  5.  
  6. var testList = new List<int>();
  7.  
  8. var s = new Stopwatch();
  9.  
  10. s.Start ();
  11. foreach (int i in arr) {
  12. if (i % 3 == 0) testList.Add (i);
  13. }
  14. s.Stop (
  15.  
  16. Console.WriteLine ("Foreach:\t{0} ticks", s.ElapsedTicks);
  17.  
  18. s.Restart ();
  19. var testLinq =
  20. from i in arr
  21. where i % 3 == 0
  22. select i;
  23. s.Stop ();
  24.  
  25. Console.WriteLine ("Linq:\t\t{0} ticks", s.ElapsedTicks);
Add Comment
Please, Sign In to add comment