-
-
Save mkrueger/89b40f6167b164238c455fd04e87b961 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Linq; | |
namespace NetCoreConsoleAp | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
List<int> list = new List<int>(); | |
Random rnd = new Random(); | |
for (int i = 0; i < 100000000; i++) | |
list.Add(i); | |
long l = 0; | |
var sw = new Stopwatch(); | |
sw.Start(); | |
foreach (var a in list.Where(i => i < 1000)) | |
{ | |
unchecked { l += a; } | |
} | |
sw.Stop(); | |
Console.WriteLine("LINQ:" + sw.ElapsedMilliseconds); | |
sw.Restart(); | |
foreach (var a in list) | |
{ | |
if (a >= 1000) continue; | |
unchecked { l += a; } | |
} | |
sw.Stop(); | |
Console.WriteLine("Foreach:" + sw.ElapsedMilliseconds); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment