using System.Diagnostics;
using System.Collections.Generic;
public static void Main() { Linq.Run(null); }
public static void Run(string[] args) { Grouping(args); }
private static void Grouping(string[] args)
Stopwatch now = new Stopwatch();
Person[] Persons = Person.Persons;
Console.WriteLine("Created , Count = {0} and Time = {1}ms",
Persons.Length.ToString("N"),now.ElapsedMilliseconds);
var it = from p in Persons group p by p.Job;
Console.WriteLine("Grouped , Count = {0} and Time = {1}ms and Ticks = {2}",
it.Count(),now.ElapsedMilliseconds,now.ElapsedTicks);
private const int GroupCount = 30;
static int PersonCount = 1000;
static int Shuffling = 10000;
public Person(int id, string name, string job)
public void Shuffle(Person it)
public static Person[] Persons
Random random = new Random();
List<Person> Box = new List<Person>();
for (int x = 0; x < GroupCount; x++)
string job = x.ToString() + ":" + random.Next(10000, 40000).ToString();
for (int y = 0; y < PersonCount; y++)
Box.Add(new Person(y, y.ToString(), job));
int max = GroupCount * PersonCount;
for (int x = 0; x < Shuffling; x++)
int one = random.Next(0, max);
int two = random.Next(0, max);
Box[one].Shuffle(Box[two]);