一、编译环境python
JetBrains PyCharm Community Edition 2018 、 Python 3.7函数
二、读文件到缓冲区(process_file(dst))性能
三、处理缓冲区,返回存有词频数据的字典(process_buffer(bvffer))spa
四、输出词频前十的单词(output_result(word_freq))3d
五、主函数对以前的函数进行整合(main())blog
python代码编写时,不须要{ }括号,用:及缩进代替,用来强制规范代码排序
例:get
try: it
doc=open(dst,'r')io
except IOError as s:
print(s)
return None
一、总运行时间:
二、执行次数最多的部分代码
可见word_freq[word] = word_freq.get(word, 0) + 1运行次数最多
三、执行时间最多的部分代码
可视化部分:
根据运行次数排序方式分析命令:
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