同样的1000万数组的排序算法为什么C# 用时0.5秒,而C语言用时0.6秒?
C语言 算法库
C#调用范例: [DllImport("BwsyqIndex.dll")] public static extern void HzSort(int[] mi, int num_elements);
protected void Page_Load(object sender, EventArgs e) { int iUp = 1000000; Random ro = new Random(10000000); long tick = DateTime.Now.Ticks;
int[] a = new int[10000000]; for (int i = 0; i < 10000000; i++) { a[i] = ro.Next(10000000); } //开始时间 TimeSpan runTime = new TimeSpan(DateTime.Now.Ticks);
HzSort(a, 10000000);
//结束时间 TimeSpan timeNow = new TimeSpan(DateTime.Now.Ticks); //时间间隔 TimeSpan ts = timeNow.Subtract(runTime).Duration(); Response.Write(" 用时:" + ts.TotalSeconds.ToString() + "秒 " + ts.TotalMilliseconds.ToString() + "毫秒");
}
|
请发表评论