# 排序算法大数据量测试代码

+关注继续查看

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Diagnostics;
using System.IO;
namespace Sort
{
class Program
{
static string ErrMsg = string.Empty;
static void Main(string[] args)
{
string[] str = { "MergeSorter", "HeapSorter", "ShellSorter", "InsertSorter", "SelectSorter", "CockTailSorter", "BubbleSorter", "QuickSorter" };
foreach(string name in str)
{
int number =20000;
for (int i = 0; i < 5;i++ )
{
number = number + 20000;
EfficiencyTest(number, 1,name);
}
}

}
//<生成随机数GenerateRandomNumber>
public static List<int> GenerateRandomNumber(int Length)
{
List<int> newRandom = new List<int>();
Random rd = new Random();
for (int i = 0; i < Length; i++)
{
}
return newRandom;
}
//测试各个排序算法效率
private static void  EfficiencyTest(int i, int j, string Name)
{
double AverageTime = 0; ;
string Cname = null;
for (int n = 0; n < j; n++)
{
int[] de = GenerateRandomNumber(i).ToArray();
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
DateTime dateStart = DateTime.Now;
switch (Name)
{
case "MergeSorter":
MergeSorter.Sort(de);
Cname = "MergeSorter";
break;
case "HeapSorter":
HeapSorter.Sort(de);
Cname = "HeapSorter";
break;
case "ShellSorter":
ShellSorter.Sort(de);
Cname = "ShellSorter";
break;
case "InsertSorter":
InsertSorter.Sort(de);
Cname = "InsertSorter";
break;
case "SelectSorter":
SelectSorter.Sort(de);
Cname = "SelectSorter";
break;
case "CockTailSorter":
CockTailSorter.Sort(de);
Cname = "CockTailSorter";
break;
case "BubbleSorter":
BubbleSorter.Sort(de);
Cname = "BubbleSorter";
break;
case "QuickSorter":
QuickSorter.Sort(de);
Cname = "QuickSorter";
break;
}
stopwatch.Stop();
AverageTime = (DateTime.Now - dateStart).TotalMilliseconds;
}
Double span = AverageTime / j;
string str = Cname + "排序" + i + "个数" + j + "次所用平均时间为：" + span + " 毫秒";
WriteFile(str,"", out ErrMsg);
}
#region 记录文本文件日志方法
/// <summary>
/// 记录文本文件日志方法
/// </summary>
/// <param name="FileContent">需要记录的文件内容</param>
/// <param name="TxtFileName">保存的文件名</param>
/// <param name="ErrMsg">错误信息</param>
/// <returns></returns>
private static bool WriteFile(string FileContent, string TxtFileName, out string ErrMsg)
{
ErrMsg = string.Empty;
StreamWriter writer = null;
string sCurDate = System.DateTime.Now.ToString("yyyy-MM-dd");
string sFile = "D:\\Log\\Log001.txt";
try
{
if (File.Exists(sFile))
writer = new StreamWriter(sFile, true, System.Text.Encoding.GetEncoding("UTF-8"));
else
writer = new StreamWriter(sFile, false, System.Text.Encoding.GetEncoding("UTF-8"));
string sDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:sss");
writer.WriteLine("<" + sDateTime + "> " + " " + FileContent);
}
catch (IOException e)
{
ErrMsg = e.Message;
return false;
}
finally
{
if (writer != null)
writer.Close();
}
return true;
}
#endregion
}
}

【高质量代码】如何写出更高质量的C/C++代码（2）：函数设计

844 0

30 0
DL之RNN：人工智能为你写代码——基于TF利用RNN算法实现生成编程语言代码(C++语言)、训练&测试过程全记录（二）
DL之RNN：人工智能为你写代码——基于TF利用RNN算法实现生成编程语言代码(C++语言)、训练&测试过程全记录
29 0

感觉好久没有写排序程序了，C语言有qsort()函数，C++有sort()函数，java语言有Arrays类(主要这个不是Array)。今天写了一下归并排序还有点费劲呀。晚上回来写写。 　　归并排序就是采用分治法进行排序： 　　(1)将一个数组分成小的2个数组分别进行排序； 　　(2)之后...
860 0
C实现特定字符串数据的排序与输出

847 0
+关注

http://blog.csdn.net/jiankunking
701

0

《2021云上架构与运维峰会演讲合集》

《零基础CSS入门教程》

《零基础HTML入门教程》