/
combineOutputs.py
158 lines (110 loc) · 4.12 KB
/
combineOutputs.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
from collections import defaultdict
import re
import numpy
def intWithCommas(x):
if type(x) not in [type(0), type(0L)]:
raise TypeError("Parameter must be an integer.")
if x < 0:
return '-' + intWithCommas(-x)
result = ''
while x >= 1000:
x, r = divmod(x, 1000)
result = ",%03d%s" % (r, result)
return "%d%s" % (x, result)
def writeLatexTableRowToFile(f, curKey, CPU_Dict, Wall_Dict, Bytes_Sent_Dict, Bytes_Received_Dict):
listMean = numpy.mean(CPU_Dict[curKey])
f.write("& $%.2f$ " % listMean)
listMean = numpy.mean(Wall_Dict[curKey])
f.write("& $%.2f$ " % listMean)
listMean = numpy.mean(Bytes_Sent_Dict[curKey])
f.write("& $" + intWithCommas(int(listMean)) + "$ ")
listMean = numpy.mean(Bytes_Received_Dict[curKey])
f.write("& $" + intWithCommas(int(listMean)) + "$ \\\\\n")
def getMeasurementFromString(inputStr):
return float(re.split(':|=',inputStr)[-1])
def fileWriteStats(f, listToStat):
listMean = numpy.mean(listToStat)
listStd = numpy.std(listToStat)
f.write("Mean : %.2f\n" % listMean)
f.write("Std Dev : %.2f\n" % listStd)
def printMeanAndStdDev(listToStat):
listMean = numpy.mean(listToStat)
listStd = numpy.std(listToStat)
print "Mean : " + str(listMean)
print "Std Dev : " + str(listStd) + "\n"
def getFileAsStringArray(filepath):
toReturn = []
with open(filepath, 'r') as content_file:
content = content_file.read()
splitFile = content.split("\n")
filteredReturn = filter(None, splitFile)
for line in filteredReturn:
if(line[0] in infoTags):
toReturn.append(line)
return toReturn
def processOneSet(protocolNum, circuitNum, partyID):
numTests = 100
ordering = []
protocolName = protocolNameList[protocolNum]
circuitName = circuitNameList[circuitNum]
CPU_Dict = defaultdict(list)
Wall_Dict = defaultdict(list)
Bytes_Sent_Dict = defaultdict(list)
Bytes_Received_Dict = defaultdict(list)
for i in range(0, numTests):
outputNumber = str(i).zfill(4)
OutputFile = "../MORE_RESULTS/Output_" + circuitName + "_" + str(partyID) + "_" + protocolName + "_" + outputNumber + ".txt"
fileAsArray = getFileAsStringArray(OutputFile)
j = 0
while( j < len(fileAsArray)):
incrementBy = 1
line = fileAsArray[j]
truncatedLine = line[4:]
if(fileAsArray[j + 3][0] in commTags):
if truncatedLine not in CPU_Dict:
ordering.append(truncatedLine)
CPU_Dict[truncatedLine].append( float(fileAsArray[j + 1][16:]) )
Wall_Dict[truncatedLine].append( float(fileAsArray[j + 2][16:]) )
Bytes_Sent_Dict[truncatedLine].append(getMeasurementFromString(fileAsArray[j + 3]))
Bytes_Received_Dict[truncatedLine].append(getMeasurementFromString(fileAsArray[j + 4]))
incrementBy = 5
else:
if(protocolNum == 2):
if(truncatedLine == 'Circuit building complete' or
truncatedLine == 'Circuit building preparation complete'):
if truncatedLine not in CPU_Dict:
ordering.append(truncatedLine)
CPU_Dict[truncatedLine].append( float(fileAsArray[j + 1][16:]) )
Wall_Dict[truncatedLine].append( float(fileAsArray[j + 2][16:]) )
Bytes_Sent_Dict[truncatedLine].append(0)
Bytes_Received_Dict[truncatedLine].append(0)
incrementBy = 3
j += incrementBy
outputFile = "./StatResults/Stats_" + circuitName + "_" + str(partyID) + "_" + protocolName + ".txt"
f = open(outputFile, 'w')
for key in ordering:
f.write(key + "\n")
'''
f.write("CPU Time\n")
fileWriteStats(f, CPU_Dict[key])
f.write("\nWall Time\n")
fileWriteStats(f, Wall_Dict[key])
f.write("\nBytes Sent\n")
fileWriteStats(f, Bytes_Sent_Dict[key])
f.write("\nBytes Received\n")
fileWriteStats(f, Bytes_Received_Dict[key])
f.write("\n")
'''
writeLatexTableRowToFile(f, key, CPU_Dict, Wall_Dict, Bytes_Sent_Dict, Bytes_Received_Dict)
f.write("\n\n")
f.close()
commTags = ['#', ':']
infoTags = ['#', ':', '+']
protocolNameList = ["LP_2010", "L_2013", "HKE_2013", "CHIMERA_2013"]
circuitNameList = ["adder_32bit", "multiplication_32bit", "AES-non-expanded"]
protocolNum = 3
circuitNum = 0
partyID = 0
for partyID in range(0, 2):
for circuitNum in range(0, 3):
processOneSet(protocolNum, circuitNum, partyID)