private void Test_SortSpeed(int length) { try { ILArray <double> ResILN = null, ResCLR = null, A = null; long durILN = 0, durCLR = 0; Misc.ILPerformer p = new ILNumerics.Misc.ILPerformer(); for (int i = 0; i < 10; i++) { A = ILMath.randn(length, 1); p.Tic(); ILMath.sort(A); p.Toc(); durILN += p.Duration; ResCLR = A.C; p.Tic(); Array.Sort(ResCLR.m_data); p.Toc(); durCLR += p.Duration; } ResILN = ILMath.sort(A); if (!ResCLR.Equals(ResILN)) { throw new Exception("invalid values!"); } Info(String.Format("ILNumerics.Net sort {1} needed: {0}ms", durILN / 10, A.Dimensions.ToString())); Info(String.Format("CLR Array.Sort {1} needed: {0}ms", durCLR / 10, A.Dimensions.ToString())); // descending durCLR = 0; durILN = 0; IComparer comparer = new DescComparerDouble(); for (int i = 0; i < 10; i++) { A = ILMath.randn(length, 1); p.Tic(); ResILN = ILMath.sort(A, true); p.Toc(); durILN += p.Duration; ResCLR = A.C; p.Tic(); Array.Sort(ResCLR.m_data, comparer); p.Toc(); durCLR += p.Duration; } if (!ResCLR.Equals(ResILN)) { throw new Exception("invalid values!"); } Info(String.Format("ILNumerics.Net sort {1} desc, needed: {0}ms", durILN / 10, A.Dimensions.ToString())); Info(String.Format("CLR Array.Sort {1} desc, needed: {0}ms", durCLR / 10, A.Dimensions.ToString())); } catch (Exception e) { Error(0, e.Message); } }
private void Test_SortSpeed(int length) { try { ILArray<double> ResILN = null, ResCLR = null, A = null; long durILN = 0, durCLR = 0; Misc.ILPerformer p = new ILNumerics.Misc.ILPerformer(); for (int i = 0; i < 10; i++) { A = ILMath.randn(length,1); p.Tic(); ILMath.sort(A); p.Toc(); durILN += p.Duration; ResCLR = A.C; p.Tic(); Array.Sort(ResCLR.m_data); p.Toc(); durCLR += p.Duration; } ResILN = ILMath.sort(A); if (!ResCLR.Equals(ResILN)) throw new Exception("invalid values!"); Info(String.Format("ILNumerics.Net sort {1} needed: {0}ms",durILN / 10,A.Dimensions.ToString())); Info(String.Format("CLR Array.Sort {1} needed: {0}ms",durCLR / 10,A.Dimensions.ToString())); // descending durCLR = 0; durILN = 0; IComparer comparer = new DescComparerDouble(); for (int i = 0; i < 10; i++) { A = ILMath.randn(length,1); p.Tic(); ResILN = ILMath.sort(A,true); p.Toc(); durILN += p.Duration; ResCLR = A.C; p.Tic(); Array.Sort(ResCLR.m_data,comparer); p.Toc(); durCLR += p.Duration; } if (!ResCLR.Equals(ResILN)) throw new Exception("invalid values!"); Info(String.Format("ILNumerics.Net sort {1} desc, needed: {0}ms",durILN / 10,A.Dimensions.ToString())); Info(String.Format("CLR Array.Sort {1} desc, needed: {0}ms",durCLR / 10,A.Dimensions.ToString())); } catch (Exception e) { Error(0, e.Message); } }