private static void MergeTest(int count, int spread) { var arrays = new List <int> [spread]; for (int i = 0; i < spread; i++) { arrays[i] = new List <int>(count / spread); } for (int i = 0; i < count; i++) { arrays[i % spread].Add(i); } for (int i = 0; i < spread; i++) { arrays[i].Sort(); } var clock = new Stopwatch(); clock.Reset(); clock.Start(); var result = LinqCollections.Merge((a, b) => a - b, false, arrays).ToList(); clock.Stop(); Console.WriteLine("{0}\t{1}", count, clock.ElapsedMilliseconds); }
public void CanMerge2Arrays() { var array1 = Enumerable.Range(0, 10).Where(i => (i & 1) == 1).ToList(); var array2 = Enumerable.Range(0, 10).Where(i => (i & 1) == 0).ToList(); var result = LinqCollections.Merge((a, b) => a - b, array1, array2).ToList(); Assert.AreEqual(array1.Count + array2.Count, result.Count); for (int i = 1; i < result.Count; i++) { Assert.IsTrue(result[i - 1] <= result[i]); } }
public void CanMergeSimple() { var array1 = Enumerable.Range(0, 1000).Select(i => 2).ToList(); var array2 = Enumerable.Range(0, 1000).Select(i => 1).ToList(); var clock = new Stopwatch(); clock.Reset(); clock.Start(); var result = LinqCollections.Merge((a, b) => a - b, array1, array2).ToList(); clock.Stop(); Assert.AreEqual(array1.Count + array2.Count, result.Count); for (int i = 1; i < result.Count; i++) { Assert.IsTrue(result[i - 1] <= result[i]); } }