- 1、本文档共9页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
代码测试cpu分析
编码测试cpu的运行速度实验人:时间时间:代码来自某大神的博客圈!!编码工具:VS2010,需要对.NET4.0支持。编码语言:c#测试原理:字符串相关度计算是文本处理和数据挖掘中一个不可或缺的方法,Levenshtein Distance可以用来比较两个字符串的相似度,即两个字符串之间的“距离”。这个“距离”其实就是从源字符串变换到目标字符串需要进行的删除、插入和替换的次数。算法简图如下:即:随机生成1000个1000长度的字符串,并比较字符串相关度。实验代码:C#:/*比较1000长度字符串的相关度,计算cpu并串行计算时间*性能比计算为10000d/运算所用时间*运算时间越短,性能比值越大,cpu性能越高*/namespace SpeedTest{using System;using System.Diagnostics;using System.Text;using System.Threading.Tasks;internalclassProgram { #region Methodsprivatestaticvoid Main(string[] args) {var watch =newStopwatch();constlong count = 1000;constint length = 1000;string comparestring = StringDistance.GenerateRandomString(length);var strlist = newstring[count]; var steps = newint[count];// prepare string[] for comparison Parallel.For(0, count, i = strlist[i] = StringDistance.GenerateRandomString(length));Console.WriteLine(已经生成 + count + 个长度为 + length + 的字符串); watch.Start();for (int i = 0; i count; i++) { steps[i] = StringDistance.LevenshteinDistance(comparestring, strlist[i]); } watch.Stop();Console.WriteLine(完成非并行计算,耗时(ms)+watch.ElapsedMilliseconds);Console.WriteLine(性能比 + 100000d/watch.ElapsedMilliseconds); watch.Reset(); watch.Start();Parallel.For( 0, count, delegate(long i) { steps[i] = StringDistance.LevenshteinDistance(comparestring, strlist[i]); }); watch.Stop();Console.WriteLine(完成并行计算,耗时(ms) + watch.ElapsedMilliseconds);Console.WriteLine(性能比+ 100000d / watch.ElapsedMilliseconds);Console.ReadKey(); } #endregion }internalclassStringDistance { #region Public Methodspublicstaticstring GenerateRandomString(int length) {var r = newRandom((int)DateTime.Now.Ticks);var sb = newStringBuilder(length);for (int i = 0; i length; i++) {int c = r.Next(97, 123); sb.Append(Char.ConvertFromUtf32(c)); }return sb.ToString(); }publicstaticint LevenshteinDistance(string str1, string
您可能关注的文档
最近下载
- 构建面向智能化时代的先进存力中心 2024.pdf
- 2023年放射医学技术考试:放射主管技师相关专业知识真题模拟汇编(共759题).doc VIP
- 《ISO IWA 48-2024ESG实施框架》中文版.docx
- 高一政治必修一:重点知识点总结.pdf
- 医院信息科工程师面试题及参考答案结构化面试题.docx VIP
- 2023年湖南省长沙市长培中学小升初英语模拟试卷及答案解析.pdf VIP
- ORTEC高纯锗谱仪技术手册(final).pdf
- third-wave-AdvantEdge实例说明教程文件.doc
- 红色喜庆风优秀员工表彰PPT模板.pptx VIP
- 苏Z01-2002 城市道路标准图集.docx
文档评论(0)