最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

SEO心得admin64浏览0评论
本文介绍了您如何运行和比较两种排序算法,看看哪种算法最先完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否需要并行处理?

推荐答案

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

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.

发布评论

评论列表(0)

  1. 暂无评论