Hyluss

PerformanceTest Lambda vs for (int[] TAB)

Sep 15th, 2017
283
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.57 KB | None | 0 0
  1. using System.Diagnostics;
  2.         // ...
  3.  
  4.         int[] tab = new int[10000];
  5.         tab[9970] = 6;
  6.  
  7.         Stopwatch sw = new Stopwatch();
  8.         sw.Start();
  9.  
  10.         // ...
  11.  
  12.         sw.Stop();
  13.         Console.WriteLine("Elapsed={0}",sw.Elapsed);
  14.  
  15. ----------------------
  16. //int v = tab.Select((value) => new {value}).Where(x => x.value >= 5).First().value;
  17. --------------
  18. Time: 00:00:00:0086460
  19. --------------
  20. /*
  21. for (int i=0; i<tab.length; i++)
  22. {
  23.     if(tab[i] >=5)
  24.     {
  25.         int v = tab[i];
  26.         break;
  27.     }
  28. }
  29. */
  30. ------------------
  31. Time: 00:00:00:0000504
  32. ------------------
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment