软件工程 效能分析

通过参考:白马学软件开发 Python中使用cProfile
[http://www.cnblogs.com/xiadw/p/7455513.html]学习了argparse模块。

要求0:用ptime.exe,连续三次运行,时间分别是:1.144s、1.176s、1.178s。

(10月8日修改:改了部分代码,可以转成utf-8,速度提高)要求0:用ptime.exe,连续三次运行,时间分别是:0.667s、0.668s、0.687s。

截图:

 

 

 

要求1

在上周的基础上修改了re.split功能的语句,感觉对消耗时间没什么作用,但是能识别带连字符的单词和带"'"的缩写。

要求2

根据老师给的作业参考资料,在cmd中输入以下命令:

python -m cProfile wf.py war_and_peace.txt

得到分析结果:

 

 

 代码片段:

file_name_word_list = re.split("[^A-Za-z0-9_’-]+",file_name_word.lower())
file_name_word_list_t = collections.Counter(file_name_word_list)
l = k.strip('()').replace("'", "").replace(",", "")

要求3

自己觉得无法再优化速度了,bug和不符合要求的地方还有很多,正在学习和编写实现功能三的代码。

代码地址:https://git.coding.net/songyuu/wf.git

 

原文地址:https://www.cnblogs.com/songyuu/p/7597767.html