-
Notifications
You must be signed in to change notification settings - Fork 0
/
time.py
57 lines (51 loc) · 1.67 KB
/
time.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
"""
Written by Dietrich
Usage: python time.py number_of_iterations [bin_commands ...]
"""
from encodings import utf_8
from msilib.schema import File
import sys
import random
import subprocess
import time
import asyncio
import typing
import datetime
def help():
print("Usage: python time.py number_of_iterations")
# Get results of communicating with the program async
async def write_results(program : subprocess.Popen[bytes], file : typing.IO):
output = program.communicate()
output = [str(x) for x in output[0].split("\n")]
for item in output:
item = item.strip()
if len(item) == 0:
continue
file.write("%s\n"%item)
# Get the result of a single file
async def process_bin(bin : str, file : typing.IO):
loop = asyncio.get_event_loop()
program = subprocess.Popen(["cargo", "+nightly", "run", "--quiet", "--bin", bin, "resources/scenes/bunnyscene.glb"],
stdout=subprocess.PIPE, stderr=subprocess.PIPE, encoding="utf8")
# Actually setup the async operation
file.write("---" + bin + "---\n")
loop.create_task(write_results(program, file))
time.sleep(50) # Some arbitrary wait time, apparently 50s is reasonable?
program.terminate()
def main():
if len(sys.argv) < 2 or not sys.argv[1].isdigit():
help()
return
bin_commands = []
with open("bins.txt", "r") as f:
for line in f:
bin_commands.append(line.strip())
bin_commands *= int(sys.argv[1])
random.shuffle(bin_commands)
filename = datetime.datetime.now().strftime(f"%Y-%m-%d-%H-%M")
with open("results/" + filename + ".result", "w") as file:
for bin in bin_commands:
print("Processing " + bin)
asyncio.run(process_bin(bin, file))
if __name__ == "__main__":
main()