20180925-3 效能分析

此作业的要求参见https://edu.cnblogs.com/campus/nenu/2018fall/homework/2145

对上周作业中的功能4 (仅由文件重定向读入,不由控制台读入) 做效能分析,以[https://coding.net/u/younggift/p/word_count_demo/git/blob/master/war_and_peace.txt]为输入数据。

测试用例:《战争与和平》,以https://coding.net/u/younggift/p/word_count_demo/git/blob/master/war_and_peace.txt 为输入数据。
分析工具:ptime.exe

本机测试环境:

CPU: 英特尔 Xeon(至强) E3-1270 v3 @ 3.50GHz 

次数 消耗时间(s)
第一次 0.452s
第二次 0.443s
第三次 0.440s
平均时间 0.445s

 

 

 

找出瓶颈:

 a = get_words('F:/wf/123.txt')
    for file in file_list:
        print(file)
        a = get_words(file)
        print("total    %d" % len(a))                        #输出统计词汇总数
        print()
        a10 = collections.Counter.most_common(a, 10)            #规定a的长度为10
        #print(a10)
        # l = sorted(a.items(), key=operator.itemgetter(0), reverse=True)

尽力而为的修改程序:

文中有多余输出,注释掉可以减少一点程序运行时间。

 

 

CPU数据:

 

 

次数 消耗时间(s)
第一次 0.439s
第二次 0.438s
第三次 0.439s
平均时间(大约) 0.4386s

相对第一次的平均时间差,减少了0.0064s

 

posted @ 2018-10-08 02:07  杨金铭  阅读(134)  评论(0编辑  收藏  举报