-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
237 lines (236 loc) · 9.17 KB
/
main.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
import os,threading,shutil,json,time
source="code"
def testc():
shutil.copy(source+"/c.c","tmp/c.c")
time.sleep(1)
os.popen("gcc tmp/c.c -o tmp/testc")
time.sleep(1)
result=[]
for i in range(0,100):
value=json.loads(os.popen("./tmp/testc").read())[0]
print("C completed once used {}s".format(value))
result.append(value)
print("C completed all tasks used {}s".format(sum(result)))
with open("rec/c.txt","a+") as fb:
fb.write(json.dumps(result))
fb.write("\nTotally used:{} Average:{}".format(sum(result),sum(result)/len(result)))
fb.write("\n----------------\n")
def testcpp():
shutil.copy(source+"/cpp.cpp","tmp/cpp.cpp")
time.sleep(1)
os.popen("g++ tmp/cpp.cpp -o tmp/testcpp")
time.sleep(1)
result=[]
for i in range(0,100):
value=json.loads(os.popen("./tmp/testcpp").read())[0]
print("C++ completed once used {}s".format(value))
result.append(value)
print("C++ completed all tasks used {}s".format(sum(result)))
with open("rec/cpp.txt","a+") as fb:
fb.write(json.dumps(result))
fb.write("\nTotally used:{} Average:{}".format(sum(result),sum(result)/len(result)))
fb.write("\n----------------\n")
def testjava():
shutil.copy(source+"/java.java","tmp/java.java")
time.sleep(1)
result=[]
for i in range(0,100):
value=json.loads(os.popen("java tmp/java.java").read())[0]
print("Java completed once used {}s".format(value))
result.append(value)
print("Java completed all tasks used {}s".format(sum(result)))
with open("rec/java.txt","a+") as fb:
fb.write(json.dumps(result))
fb.write("\nTotally used:{} Average:{}".format(sum(result),sum(result)/len(result)))
fb.write("\n----------------\n")
def testgo():
shutil.copy(source+"/go.go","tmp/go.go")
time.sleep(1)
os.popen("go build -o tmp/go tmp/go.go")
time.sleep(1)
result=[]
for i in range(0,100):
value=json.loads(os.popen("./tmp/go").read())[0]
print("Go completed once used {}s".format(value))
result.append(value)
print("Go completed all tasks used {}s".format(sum(result)))
with open("rec/go.txt","a+") as fb:
fb.write(json.dumps(result))
fb.write("\nTotally used:{} Average:{}".format(sum(result),sum(result)/len(result)))
fb.write("\n----------------\n")
def testjs():
shutil.copy(source+"/javascript.js","tmp/javascript.js")
time.sleep(1)
result=[]
for i in range(0,100):
value=json.loads(os.popen("node tmp/javascript.js").read())[0]
print("Node completed once used {}s".format(value))
result.append(value)
print("Node completed all tasks used {}s".format(sum(result)))
with open("rec/node.txt","a+") as fb:
fb.write(json.dumps(result))
fb.write("\nTotally used:{} Average:{}".format(sum(result),sum(result)/len(result)))
fb.write("\n----------------\n")
def testlua():
shutil.copy(source+"/lua.lua","tmp/lua.lua")
time.sleep(1)
result=[]
for i in range(0,100):
value=json.loads(os.popen("lua tmp/lua.lua").read())[0]
print("Lua completed once used {}s".format(value))
result.append(value)
print("Lua completed all tasks used {}s".format(sum(result)))
with open("rec/lua.txt","a+") as fb:
fb.write(json.dumps(result))
fb.write("\nTotally used:{} Average:{}".format(sum(result),sum(result)/len(result)))
fb.write("\n----------------\n")
def testlua():
shutil.copy(source+"/lua.lua","tmp/lua.lua")
time.sleep(1)
result=[]
for i in range(0,100):
value=json.loads(os.popen("lua tmp/lua.lua").read())[0]
print("Lua completed once used {}s".format(value))
result.append(value)
print("Lua completed all tasks used {}s".format(sum(result)))
with open("rec/lua.txt","a+") as fb:
fb.write(json.dumps(result))
fb.write("\nTotally used:{} Average:{}".format(sum(result),sum(result)/len(result)))
fb.write("\n----------------\n")
def testperl():
shutil.copy(source+"/perl.pl","tmp/perl.pl")
time.sleep(1)
result=[]
for i in range(0,100):
value=json.loads(os.popen("perl tmp/perl.pl").read())[0]
print("Perl completed once used {}s".format(value))
result.append(value)
print("Perl completed all tasks used {}s".format(sum(result)))
with open("rec/perl.txt","a+") as fb:
fb.write(json.dumps(result))
fb.write("\nTotally used:{} Average:{}".format(sum(result),sum(result)/len(result)))
fb.write("\n----------------\n")
def testphp():
shutil.copy(source+"/php.php","tmp/php.php")
time.sleep(1)
result=[]
for i in range(0,100):
value=json.loads(os.popen("php tmp/php.php").read())[0]
print("PHP completed once used {}s".format(value))
result.append(value)
print("PHP completed all tasks used {}s".format(sum(result)))
with open("rec/php.txt","a+") as fb:
fb.write(json.dumps(result))
fb.write("\nTotally used:{} Average:{}".format(sum(result),sum(result)/len(result)))
fb.write("\n----------------\n")
def testR():
shutil.copy(source+"/R.R","tmp/R.R")
time.sleep(1)
result=[]
for i in range(0,100):
value=json.loads(os.popen("./tmp/R.R").read()[5:-2])[0]
print("R completed once used {}s".format(value))
result.append(value)
print("R completed all tasks used {}s".format(sum(result)))
with open("rec/R.txt","a+") as fb:
fb.write(json.dumps(result))
fb.write("\nTotally used:{} Average:{}".format(sum(result),sum(result)/len(result)))
fb.write("\n----------------\n")
def testruby():
shutil.copy(source+"/ruby.rb","tmp/ruby.rb")
time.sleep(1)
result=[]
for i in range(0,100):
value=json.loads(os.popen("ruby tmp/ruby.rb").read())[0]
print("Ruby completed once used {}s".format(value))
result.append(value)
print("Ruby completed all tasks used {}s".format(sum(result)))
with open("rec/ruby.txt","a+") as fb:
fb.write(json.dumps(result))
fb.write("\nTotally used:{} Average:{}".format(sum(result),sum(result)/len(result)))
fb.write("\n----------------\n")
def testpython2():
shutil.copy(source+"/python.py","tmp/python2.py")
time.sleep(1)
result=[]
for i in range(0,100):
value=json.loads(os.popen("python tmp/python2.py").read())[0]
print("Python2 completed once used {}s".format(value))
result.append(value)
print("Python2 completed all tasks used {}s".format(sum(result)))
with open("rec/python2.txt","a+") as fb:
fb.write(json.dumps(result))
fb.write("\nTotally used:{} Average:{}".format(sum(result),sum(result)/len(result)))
fb.write("\n----------------\n")
def testpython3():
shutil.copy(source+"/python.py","tmp/python3.py")
time.sleep(1)
result=[]
for i in range(0,100):
value=json.loads(os.popen("python3 tmp/python3.py").read())[0]
print("Python3 completed once used {}s".format(value))
result.append(value)
print("Python3 completed all tasks used {}s".format(sum(result)))
with open("rec/python3.txt","a+") as fb:
fb.write(json.dumps(result))
fb.write("\nTotally used:{} Average:{}".format(sum(result),sum(result)/len(result)))
fb.write("\n----------------\n")
def testpypy():
shutil.copy(source+"/python.py","tmp/pypy.py")
time.sleep(1)
result=[]
for i in range(0,100):
value=json.loads(os.popen("pypy tmp/pypy.py").read())[0]
print("Pypy completed once used {}s".format(value))
result.append(value)
print("Pypy completed all tasks used {}s".format(sum(result)))
with open("rec/pypy.txt","a+") as fb:
fb.write(json.dumps(result))
fb.write("\nTotally used:{} Average:{}".format(sum(result),sum(result)/len(result)))
fb.write("\n----------------\n")
def testjython():
shutil.copy(source+"/python.py","tmp/jython.py")
time.sleep(1)
result=[]
for i in range(0,100):
value=json.loads(os.popen("jython tmp/jython.py").read())[0]
print("Jython completed once used {}s".format(value))
result.append(value)
print("Jython completed all tasks used {}s".format(sum(result)))
with open("rec/jython.txt","a+") as fb:
fb.write(json.dumps(result))
fb.write("\nTotally used:{} Average:{}".format(sum(result),sum(result)/len(result)))
fb.write("\n----------------\n")
def t1():
testcpp()
testjava()
testgo()
testlua()
testjython()
testperl()
testjs()
def t2():
testphp()
testR()
testruby()
testpython2()
testc()
testpython3()
testpypy()
testperl()
def main():
os.makedirs("rec",exist_ok=True)
try:
shutil.rmtree("tmp")
except:
pass
os.makedirs("tmp")
#threading.Thread(target=t1).start()
#threading.Thread(target=t2).start()
input()
testgo()
testlua()
testjython()
testperl()
testjs()
main()