第三次作业-功能测试

因为文件的编码问题,所以出现了小问题单词全部都输出了,这是三次的程序执行图

猜测程序瓶颈是读入文件,读入文件是整个程序循环次数最多的地

file_name = input("")#在命令行输出
path = "C:\\Users\\Administrator\\Desktop\\" +file_name +'.txt'
if not os.path.exists(path):
    print('请把目标文件放在桌面')
else:
    with open(path,'r',encoding='utf-8') as f:
        for line in f:
            lines_count = lines_count + 1
            chars_count = chars_count + len(line)
            match = re.findall(r'[^a-zA-Z0-9]+', line)  # 只要英文单词,删掉其他字符
            for i in match:
                line = line.replace(i, ' ')
                lines_list = line.split()  # 对单词进行统计
            for i in lines_list:
                if i not in words_dict:
                    words_dict[i] = 1
                else:
                    words_dict[i] = words_dict[i] + 1

 

性能分析我使用了pycharm自带的profile分析工具: 

因为本身的能力不足,以及时间的短暂,没办法解决,直接分析wf这个程序,所以选择的是分析其中wd这个程序,从图中我们可以看到程序最大最大的瓶颈是input板块。

 至于代码的优化,因为对python的理解还不够深入,暂时没办法实现。

 

转载于:https://www.cnblogs.com/cherishcherry/p/7597882.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值