Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var rand = new Random();
- var stufff = Enumerable.Range(1, 1000).Select(i => rand.Next(1, 100000));
- var sw = Stopwatch.StartNew();
- for (int i = 0; i < 10000; i++)
- {
- var nonNulls = stufff.Where(x => x != null);
- var dupes = nonNulls.Count() != nonNulls.Distinct().Count();
- }
- sw.Stop();
- sw.ElapsedMilliseconds.Dump("Distinct");
- var sw2 = Stopwatch.StartNew();
- for (int i = 0; i < 10000; i++)
- {
- var dupes = stufff
- .Where(item => item != null)
- .GroupBy(item => item)
- .Any(g => g.Count() > 1);
- }
- sw2.Stop();
- sw2.ElapsedMilliseconds.Dump("Count");
- var sw3 = Stopwatch.StartNew();
- for (int i = 0; i < 10000; i++)
- {
- var dupes = stufff
- .Where(item => item != null)
- .GroupBy(item => item)
- .Any(g => g.Skip(1).Any());
- }
- sw3.Stop();
- sw3.ElapsedMilliseconds.Dump("Skip");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement