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", "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++) { newRandom.Add(rd.Next()); } 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 } }
以上就是 排序算法大数据量测试代码的内容,更多相关内容请关注PHP中文网(www.php.cn)!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











1. Background of the problem 1. Introduction to the two-sided market experiment The two-sided market, that is, a platform, includes two participants, producers and consumers, and both parties promote each other. For example, Kuaishou has a video producer and a video consumer, and the two identities may overlap to a certain extent. Bilateral experiment is an experimental method that combines groups on the producer and consumer sides. Bilateral experiments have the following advantages: (1) The impact of the new strategy on two aspects can be detected simultaneously, such as changes in product DAU and the number of people uploading works. Bilateral platforms often have cross-side network effects. The more readers there are, the more active the authors will be, and the more active the authors will be, the more readers will follow. (2) Effect overflow and transfer can be detected. (3) Help us better understand the mechanism of action. The AB experiment itself cannot tell us the relationship between cause and effect, only

How to filter and sort data in Vue technology development In Vue technology development, data filtering and sorting are very common and important functions. Through data filtering and sorting, we can quickly query and display the information we need, improving user experience. This article will introduce how to filter and sort data in Vue, and provide specific code examples to help readers better understand and use these functions. 1. Data filtering Data filtering refers to filtering out data that meets the requirements based on specific conditions. In Vue, we can pass comp

Organizing | Nuka-Cola, Chu Xingjuan Friends who have taken basic computer science courses must have personally designed a sorting algorithm - that is, using code to rearrange the items in an unordered list in ascending or descending order. It's an interesting challenge, and there are many possible ways to do it. A lot of time has been invested in figuring out how to accomplish sorting tasks more efficiently. As a basic operation, sorting algorithms are built into the standard libraries of most programming languages. There are many different sorting techniques and algorithms used in code bases around the world to organize large amounts of data online, but at least as far as the C++ libraries used with the LLVM compiler are concerned, the sorting code has not changed in more than a decade. Recently, the Google DeepMindAI team has now developed a

How to use the radix sort algorithm in C++ The radix sort algorithm is a non-comparative sorting algorithm that completes sorting by dividing the elements to be sorted into a limited set of digits. In C++, we can use the radix sort algorithm to sort a set of integers. Below we will discuss in detail how to implement the radix sort algorithm, with specific code examples. Algorithm idea The idea of the radix sorting algorithm is to divide the elements to be sorted into a limited set of digital bits, and then sort the elements on each bit in turn. Sorting on each bit is completed

How to implement the selection sort algorithm in C# Selection sort (SelectionSort) is a simple and intuitive sorting algorithm. Its basic idea is to select the smallest (or largest) element from the elements to be sorted each time and put it at the end of the sorted sequence. Repeat this process until all elements are sorted. Let's learn more about how to implement the selection sort algorithm in C#, along with specific code examples. Creating a selection sort method First, we need to create a method for implementing selection sort. This method accepts a

Swoole is a high-performance network communication framework based on PHP language. It supports the implementation of multiple asynchronous IO modes and multiple advanced network protocols. On the basis of Swoole, we can use its multi-threading function to implement efficient algorithm operations, such as high-speed sorting algorithms. The high-speed sorting algorithm (QuickSort) is a common sorting algorithm. By locating a benchmark element, the elements are divided into two subsequences. Those smaller than the benchmark element are placed on the left, and those greater than or equal to the benchmark element are placed on the right. Then the left and right subsequences are placed. subsequence recursion

For different scenarios, it is crucial to choose the appropriate PHP array sorting algorithm. Bubble sort is suitable for small-scale arrays without stability requirements; quick sort has the lowest time complexity in most cases; merge sort has high stability and is suitable for scenarios that require stable results; selection sort is suitable for situations without stability requirements. Situation; Heap sort efficiently finds the maximum or minimum value. Through comparison of actual cases, quick sort is superior to other algorithms in terms of time efficiency, but merge sort should be chosen when stability needs to be considered.

Array sorting algorithms are used to arrange elements in a specific order. Common types of algorithms include: Bubble sort: swap positions by comparing adjacent elements. Selection sort: Find the smallest element and swap it to the current position. Insertion sort: Insert elements one by one to the correct position. Quick sort: divide and conquer method, select the pivot element to divide the array. Merge Sort: Divide and Conquer, Recursive Sorting and Merging Subarrays.
