Sorting algorithm large data volume test code

Source: Internet
Author: User
Sorting algorithm large data volume test code

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", "Insertso            Rter "," 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); }}}//< generate random number generaterandomnumber> public static list<int> Generaterandomnumb            ER (int Length) {list<int> newrandom = new list<int> ();            Random rd = new random ();    for (int i = 0; i < Length; i++) {            Newrandom.add (Rd.            Next ());        } return newrandom; }//test each sorting algorithm efficiency private static void efficiencytest (int i, int j, string Name) {double Ave            Ragetime = 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 + "Sort" + i + "number" + j + "Time averaged": "+ span +" milliseconds ";        WriteFile (str, "", out errmsg); #region Record text File log method///<summary>///Record text file log method////</summary>//&LT;PA Ram Name= "filecontent" > File contents to be recorded </param>//<param name= "Txtfilename" > Saved file name </param>/ <param name= "ErrMsg" > Error messages </param>//<returns></returns> private static bool Wri Tefile (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.t Ext.                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}}

The above is the sorting algorithm Big Data volume test code content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.