@
ladypxy,我这么说你肯定不服气,下面用你能理解的方式写了一个算法。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
data = """get_foo start 913912131
get_foo end 14141251132
get_abc start 12312415
get_def start 123156151
get_def end 123115112312
get_abc end 121515161
get_foo start 913912131
get_foo end 14141251132
get_abc start 12312415
get_def start 123156151
get_def end 123115112312
get_abc end 121515161
get_foo start 913912131
get_foo end 14141251132
get_abc start 12312415
get_def start 123156151
get_def end 123115112312
get_abc end 121515161
"""
i_data = (l.split() for l in data.splitlines())
result={}
for proc, flag, timestamp in i_data:
□□□□temp = result.setdefault(proc, {'sum':0,'cnt':0, 'start':0})
□□□□if flag == 'start':
□□□□□□□□temp['start']=int(timestamp)
□□□□else:
□□□□□□□□temp['sum'] += int(timestamp) - temp['start']
□□□□□□□□temp['cnt'] += 1
for p, v in result.items():
□□□□print('process:', p, 'avg time:',v['sum']/v['cnt'])