python二级备考(2)

您所在的位置:网站首页 姓名性别年龄英文 python二级备考(2)

python二级备考(2)

2024-07-16 03:58| 来源: 网络整理| 查看: 265

out.txt,其中有一些数据库操作功能的执行时间信息,如下所示:‪‪‪‪‪‪‫‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‫‪  

示例‪‪‪‪‪‪‫‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‫‪

starting,0.000037,2.102

After opening tables,0.000008,0.455

System lock,0.000004,0.227

其中第1列是操作的名字,第2列是操作所花费的时间,单位是秒,第3列是操作时间占全部过程的百分比,字段之间用逗号','隔开。‪‪‪‪‪‪‫‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‫‪  

读取out.txt文件里的内容,统计所有操作所花费的时间总和,并输出操作时间百分比最多的三个操作所占百分比的值,及其对应的操作名称,显示在屏幕上, 如下所示: .‪‪‪‪‪‪‫‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‫‪

示例‪‪‪‪‪‪‫‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‪‫‪

the total execute time is  0.001724

the top 0 percentage time is 46.023, spent in "Filling schema table" operation

the top 1 percentage time is 36.932, spent in "Sending data" operation

# 以下代码为提示框架 # 请在...处使用一行或多行代码替换 # 请在______处使用一行代码替换 # # 注意:提示框架代码可以任意修改,以完成程序功能为准 sumtime = 0 percls = [] ts = {} with open('out.txt', 'r') as f: for i in f: i=i.strip().split(',') ts[i[0]]=i[2] sumtime+=eval(i[1]) print('the total execute time is ', sumtime) tns = list(ts.items()) tns.sort(key=lambda x: x[1], reverse=True) for i in range(3): print('the top {} percentage time is {}, spent in "{}" operation'.format(i, tns[i][1],tns[i][0]))



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3