您如何运行和比较两种排序算法,看看哪种算法最先完成?

编程入门 行业动态 更新时间:2024-10-13 22:22:22
本文介绍了您如何运行和比较两种排序算法,看看哪种算法最先完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否需要并行处理?

推荐答案

使用秒表类运行一种算法,然后运行另一种算法。

Use Stopwatch class to run one algorithm and then run the other one.

Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); // Code for your algorithm stopWatch.Stop(); // Get the elapsed time as a TimeSpan value. TimeSpan ts = stopWatch.Elapsed; // Format and display the TimeSpan value. string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10);

请确保您使用大量输入来测试算法。在小集合上执行比其他算法更快的排序算法,不一定在大集合上执行更快。

Make sure you test your algorithm with numerous size inputs. A sorting algorithm which performs faster than another algorithm on small set may not necessarily perform faster on a larger set.

更多推荐

您如何运行和比较两种排序算法,看看哪种算法最先完成?

本文发布于:2023-11-30 16:04:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650620.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:算法   两种   哪种

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!