-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythonbench.py
More file actions
160 lines (144 loc) · 4.46 KB
/
pythonbench.py
File metadata and controls
160 lines (144 loc) · 4.46 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
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
157
import math
import time
import sys
element = 0
iteration = 0
innerloop = 0
total = float(0.0)
array_length = 10000000
array = [i for i in range(array_length)]
upperrange = 10000000
w = float(0.999999)
f = open("speedbench-python.txt", "w")
#-----------------------------------------------------------------------
print"Python speed test begins..."
#-----------------------------------------------------------------------
pstart = time.clock()
answer=w
t0 = time.clock()
for x in range(0, upperrange):
answer = math.sqrt(answer)
timer1=time.clock() - t0
print"Sqrt of %5f is %+11.6e Time = %5f seconds." %(w,answer,timer1)
f.write("Sqrt %5f" %(timer1))
f.write("\n")
#-----------------------------------------------------------------------
answer=w
t0 = time.clock()
for x in range(0, upperrange):
answer = float(math.sin(answer))
timer1=time.clock() - t0
print"Sin of %5f is %+11.6e Time = %5f seconds." %(w,answer,timer1)
f.write("Sin %5f" %(timer1))
f.write("\n")
#-----------------------------------------------------------------------
answer=w
t0 = time.clock()
for x in range(0, upperrange):
answer = math.exp(-answer)
timer1=time.clock() - t0
print"Exp of %5f is %+11.6e Time = %5f seconds." %(w,answer,timer1)
f.write("Exp %5f" %(timer1))
f.write("\n")
#-----------------------------------------------------------------------
answer=w
t0 = time.clock()
for x in range(0, upperrange):
answer = math.log(1+abs(answer))
timer1=time.clock() - t0
print"Ln of %5f is %+11.6e Time = %5f seconds." %(w,answer,timer1)
f.write("Ln %5f" %(timer1))
f.write("\n")
#-----------------------------------------------------------------------
answer=w
t0 = time.clock()
for x in range(0, upperrange):
answer = math.cos(answer)
timer1=time.clock() - t0
print"Cos of %5f is %+11.6e Time = %5f seconds." %(w,answer,timer1)
f.write("Cos %5f" %(timer1))
f.write("\n")
#-----------------------------------------------------------------------
answer=w
t0 = time.clock()
for x in range(0, upperrange):
answer =answer** 4
timer1=time.clock() - t0
print"x^4 of %5f is %+11.6e Time = %5f seconds." %(w,answer,timer1)
f.write("x^4 %5f" %(timer1))
f.write("\n")
#-----------------------------------------------------------------------
answer=w
t0 = time.clock()
for x in range(0, upperrange):
answer = answer*w
timer1=time.clock() - t0
print"x*x of %5f is %+11.6e Time = %5f seconds." %(w,answer,timer1)
f.write("x*x %5f" %(timer1))
f.write("\n")
#-----------------------------------------------------------------------
answer=w
t0 = time.clock()
for x in range(0, upperrange):
answer = answer/w
timer1=time.clock() - t0
print"x/x of %5f is %+11.6e Time = %5f seconds." %(w,answer,timer1)
f.write("x/x %5f" %(timer1))
f.write("\n")
#-----------------------------------------------------------------------
answer=w
t0 = time.clock()
for x in range(0, upperrange):
answer = answer+w
timer1=time.clock() - t0
print"x+x of %5f is %+11.6e Time = %5f seconds." %(w,answer,timer1)
f.write("x+x %5f" %(timer1))
f.write("\n")
#-----------------------------------------------------------------------
answer=w
t0 = time.clock()
for x in range(0, upperrange):
answer = answer-w
timer1=time.clock() - t0
print"x-x of %5f is %+11.6e Time = %5f seconds." %(w,answer,timer1)
f.write("x-x %5f" %(timer1))
f.write("\n")
#-----------------------------------------------------------------------
answer = w
t0 = time.clock()
for x in range(0, upperrange):
answer = math.sqrt(answer)
answer = math.sin(answer)
answer = math.exp(-answer)
answer = math.log(1+abs(answer))
answer = math.cos(answer)
answer = answer ** 4
answer = answer*w
answer = answer/w
answer = answer+w
answer = answer-w
timer1=time.clock() - t0
print"Loop of %5f is %+11.6e Time = %5f seconds." %(w,answer,timer1)
f.write("Loop %5f" %(timer1))
f.write("\n")
#-----------------------------------------------------------------------
iterations=10
t0 = time.clock()
while iteration < iterations:
innerloop = 0
while innerloop < 10000000:
total += array[(iteration + innerloop) % array_length];
innerloop += 1
iteration += 1
del array
timer1=time.clock() - t0
print"Array of %d is %+11.6e Time = %5f seconds." %(iterations,total,timer1)
f.write("Array %5f" %(timer1))
f.write("\n")
#-----------------------------------------------------------------------
timer1=time.clock() - pstart
print"IRun Time = %5f seconds." %(timer1)
f.write("IRun %5f" %(timer1))
f.write("\n")
print"Done"
f.close()