private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) { TestInfo testInfo = (TestInfo)e.Argument; IEnumerable <TestDataElement> testData = Enumerator.Generate(testInfo.SourceCount, X => new TestDataElement(X)); if (testInfo.SourceOrder == 0) { testData = testData.Shuffle(); } else { testData = PreSortTestData(testData, testInfo); } TestDataElement[] testArray1; TestDataElement[] testArray2; testArray1 = testData.ToArray(); testArray2 = new TestDataElement[testArray1.Length]; testArray1.CopyTo(testArray2, 0); IOrderedEnumerable <TestDataElement> standardSort = GetStandardSort(testArray1, testInfo); IComposableSortEnumerable <TestDataElement> linqLibSort = GetLinqLibSort(testArray2, testInfo); e.Cancel = DoTest(testInfo, standardSort, linqLibSort); }
/// <summary> /// Documentation /// </summary> /// <typeparam name="TSource"></typeparam> /// <typeparam name="TKey"></typeparam> /// <param name="source"></param> /// <param name="keySelector"></param> /// <param name="sortType"></param> /// <param name="comparer"></param> /// <returns></returns> public static IComposableSortEnumerable <TSource> ThenBy <TSource, TKey>(this IComposableSortEnumerable <TSource> source, Func <TSource, TKey> keySelector, SortType sortType, IComparer <TKey> comparer) { if (source == null) { throw Error.ArgumentNull("source"); } source.AppendSorter(keySelector, sortType, comparer, false); return(source); }
/// <summary> /// Documentation /// </summary> /// <typeparam name="TSource"></typeparam> /// <typeparam name="TKey"></typeparam> /// <param name="source"></param> /// <param name="keySelector"></param> /// <param name="sortType"></param> /// <returns></returns> public static IComposableSortEnumerable <TSource> ThenByDescending <TSource, TKey>(this IComposableSortEnumerable <TSource> source, Func <TSource, TKey> keySelector, SortType sortType) { if (source == null) { throw Error.ArgumentNull("source"); } source.AppendSorter(keySelector, sortType, null, true); return(source); }
private bool DoTest(TestInfo testInfo, IOrderedEnumerable <TestDataElement> standardSort, IComposableSortEnumerable <TestDataElement> linqLibSort) { Stopwatch sw = new Stopwatch(); double r1, r2; for (int i = 0; i < testInfo.TestLoops && !backgroundWorker.CancellationPending; i++) { sw.Reset(); sw.Start(); var arr1 = standardSort.ToArray(); r1 = sw.Elapsed.TotalMilliseconds; sw.Reset(); sw.Start(); var arr2 = linqLibSort.ToArray(); r2 = sw.Elapsed.TotalMilliseconds; backgroundWorker.ReportProgress(i, "Standard: " + r1.ToString() + "\r\nCustom: " + r2.ToString() + "\r\n\r\n"); if (arr1.SequenceRelation(arr2) != SequenceRelationType.Equal) { #if DEBUG for (int i1 = 0; i1 < arr1.Length; i1++) { if (arr1[i1].Index != arr2[i1].Index) { Debugger.Break(); break; } } #else backgroundWorker.ReportProgress(i, "Sort mismatch***.\r\n\r\n"); #endif } } return(backgroundWorker.CancellationPending); }