forked from verificatum/verificatum-vjsc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench.py
executable file
·65 lines (54 loc) · 1.89 KB
/
bench.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
#!/usr/bin/env python3
# Dependencies:
# sudo apt install firefox-geckodriver chromium-chromedriver python3-selenium
import os
import time
import subprocess
from tempfile import TemporaryDirectory
from selenium import webdriver
URL = r"http://localhost:8000/bench-vjsc.html"
BENCH_RULE = "bench-vjsc"
LAST_BENCH = "NaorYung"
COMMITS = (
"db76b0c80c9d0905d6189cc2bd72608d809a8cba", # original VJSC
"0b18485d00303505e1fa088bf6d829e92791c523", # .splice()
"4e88b29012be34e59271e2c4d6120d7eb6802862", # for loop
)
def main():
for driver in iter_drivers():
server = None
try:
for commit in COMMITS:
with TemporaryDirectory() as d:
# d = d.name
print(d)
subprocess.call(["git", "worktree", "add", d, commit])
subprocess.call(["make", "-C", d, BENCH_RULE])
server = subprocess.Popen(
["python3", "-m", "http.server"],
cwd=os.path.join(d, BENCH_RULE),
)
with open(
driver.capabilities["browserName"] + commit + ".html", "w"
) as f:
time.sleep(1) # XXX: hack - wait for server
print(run_tests(driver), file=f)
server.terminate()
server = None
finally:
driver.quit()
if server:
server.terminate()
def iter_drivers():
yield webdriver.Firefox()
yield webdriver.Chrome()
def run_tests(driver):
driver.get(URL)
while True:
status = driver.find_element_by_id(LAST_BENCH).text.strip().lower()
if not status.startswith("waiting") and not status.startswith("computing"):
break
time.sleep(5)
return driver.page_source
if __name__ == "__main__":
main()