软工作业 3:个人编程练习

一、程序分析 

  1、编译环境

    JetBrains PyCharm Community Edition 2018 、  Python 3.7

  2、读文件到缓冲区(process_file(dst))

  3、处理缓冲区,返回存有词频数据的字典(process_buffer(bvffer))

  4、输出词频前十的单词(output_result(word_freq))

  5、主函数对之前的函数进行整合(main())

二、代码风格说明。 

python代码编写时,不需要{ }括号,用:及缩进代替,用来强制规范代码

例:

       try: 

                doc=open(dst,'r')

       except IOError as s:

                print(s)

                return None

三、程序运行命令、运行结果截图 

四、性能分析结果及改进 

1、总运行时间:

2、执行次数最多的部分代码

可见word_freq[word] = word_freq.get(word, 0) + 1运行次数最多

3、执行时间最多的部分代码

 

 

可视化部分:

根据运行次数排序方式分析命令

                                                       python -m cProfile -o result.out -s call word_freq.py

                                                       python gprof2dot.py -f pstats result.out | dot -Tpng -o result.png

 

根据占用时间排序方式分析命令

                                                    python -m cProfile -o resultc.out -s cumulative word_freq.py

                                                    python gprof2dot.py -f pstats resultc.out | dot -Tpng -o result.png

 

posted @ 2018-10-09 20:35  周磊3711  阅读(192)  评论(0编辑  收藏  举报