-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompileTimeTest.py
More file actions
executable file
·64 lines (36 loc) · 1.44 KB
/
CompileTimeTest.py
File metadata and controls
executable file
·64 lines (36 loc) · 1.44 KB
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
#Compile Time Test
#from time import clock, time
import time, fileinput, string, sys, operator, os
from DS import *
#dataStructures = ["Arr()", "SArr()"]
dataStructures = range(DS.NUM_STRUCTURES)
dataStructureTimes = []
testFileName = "test_compile"
testFile = testFileName + ".py"
minTime = sys.maxint
for i in range(len(dataStructures)): #loop through dataStructures
newFileName = str(testFileName + "_T" + str(dataStructures[i]) + ".py")
file = open(newFileName, "w")
for line in fileinput.input(testFile): #replace SD() with a d.s.
line = line.replace("SD()", "SD(True, " + str(dataStructures[i]) + ")")
file.write(line)
file.close()
start_time = time.time()
execfile(newFileName)
elapsedTime = time.time() - start_time
dataStructureTimes.append(elapsedTime)
for i in range(len(dataStructures)): #print times
print ("Time using %s: %s" % (dataStructures[i], dataStructureTimes[i]))
minIndex, minValue = min(enumerate(dataStructureTimes), key=operator.itemgetter(1))
print "Fastest is %d" % (minIndex)
#create *_optimized.py with SD set to False
file = open(testFileName + "_optimized.py", "w")
fastestFileName = str(testFileName + "_T" + str(minIndex) + ".py")
for line in fileinput.input(fastestFileName):
line = line.replace("SD(True", "SD(False")
file.write(line)
file.close()
#remove temp testing files
for filename in os.listdir("."):
if filename.startswith(testFileName + "_T"):
os.remove(filename)