forked from ericleong/slickr
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathavg.py
More file actions
executable file
·26 lines (22 loc) · 704 Bytes
/
avg.py
File metadata and controls
executable file
·26 lines (22 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/env python
from __future__ import print_function
from collections import defaultdict
import os
import sys
import fileinput
# Calculate average separately for separate files
files = defaultdict(lambda: {"duration": 0, "lines": 0})
for line in fileinput.input():
try:
# If this fails, no entry is created
duration = sum(map(float, line.split("\t")))
f = files[os.path.basename(fileinput.filename())]
f["duration"] += duration
f["lines"] += 1
except:
pass
if len(files) > 0:
for name, result in files.iteritems():
print(name, result["duration"] / result["lines"])
else:
print("No profiling data found.", file=sys.stderr)