Skip to content

Commit c807a2a

Browse files
committed
Complete python test files that group tests by gfa size
1 parent 9231143 commit c807a2a

File tree

4 files changed

+192
-2
lines changed

4 files changed

+192
-2
lines changed

bench/filesize_benchmark.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import os
33
import json
44
import subprocess
5+
import tomllib
56

67
def benchmark(test_file):
7-
subprocess.run(["fgfa", "-I", test_file, "-o", "filesize_benchmark.txt"],
8+
subprocess.run(["target/release/fgfa", "-I", test_file, "-o", "filesize_benchmark.txt"],
89
check = True)
910
size_bytes = os.path.getsize("filesize_benchmark.txt")
1011
subprocess.run(["rm", "-rf", "filesize_benchmark.txt"], check = True)

bench/filesize_benchmark_web.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import sys
2+
import os
3+
import json
4+
import subprocess
5+
from pathlib import Path
6+
import tomllib
7+
import gzip
8+
import shutil
9+
10+
with open("bench/graphs.toml", "rb") as f:
11+
toml_graphs = tomllib.load(f)
12+
13+
hprc_dict = dict(toml_graphs["hprc"])
14+
15+
test_dict = dict(toml_graphs["test"])
16+
17+
gont_dict = dict(toml_graphs["1000gont"])
18+
19+
mini_files = [test_dict["lpa"], test_dict["chr6c4"], hprc_dict["chrM"]]
20+
21+
med_files = [hprc_dict["chr20"], hprc_dict["chrX"], gont_dict["chr16"]]
22+
23+
big_files = [hprc_dict["chrY"], hprc_dict["chr1"], hprc_dict["chr10"]]
24+
25+
results = "filesize_benchmark.txt"
26+
27+
def download_file(target_name, web_file):
28+
gzipped = False
29+
temp_name = ""
30+
if "gfa.gz" in web_file:
31+
gzipped = True
32+
if gzipped:
33+
temp_name = f"{target_name}.gz"
34+
35+
if not Path(target_name).exists():
36+
if gzipped:
37+
subprocess.run(["curl", "-o", temp_name, web_file],
38+
check = True)
39+
with gzip.open(temp_name, "rb") as f_in:
40+
with open(target_name, "wb") as f_out:
41+
shutil.copyfileobj(f_in, f_out)
42+
subprocess.run(["rm", "-rf", temp_name], check = True)
43+
else:
44+
subprocess.run(["curl", "-o", target_name, web_file],
45+
check = True)
46+
47+
def benchmark():
48+
test_config = ""
49+
test_cond = ""
50+
if len(sys.argv) >= 2:
51+
test_config = sys.argv[1] #Can be either "mini", "med", or "big"
52+
else:
53+
raise ValueError("No arguments provided")
54+
55+
if len(sys.argv) >= 3:
56+
test_cond = sys.argv[2] # Can be "del", or not provided
57+
58+
test_files = []
59+
if test_config == "mini":
60+
test_files = mini_files
61+
elif test_config == "med":
62+
test_files = med_files
63+
elif test_config == "big":
64+
test_files = big_files
65+
else:
66+
raise ValueError("Incorrect test config provided")
67+
68+
size_bytes_avg = 0
69+
i = 0
70+
for file in test_files:
71+
test_file_name = f"tests/{test_config}_{i}.gfa"
72+
download_file(test_file_name, file)
73+
subprocess.run(["target/release/fgfa", "-I", test_file_name, "-o", results],
74+
check = True)
75+
size_bytes = os.path.getsize(results)
76+
subprocess.run(["rm", "-rf", results], check = True)
77+
if test_cond == "del":
78+
subprocess.run(["rm", "-rf", test_file_name], check = True)
79+
size_bytes_avg += size_bytes
80+
i += 1
81+
size_bytes_avg /= len(test_files)
82+
return size_bytes_avg / 1000.0
83+
84+
bencher_json = {
85+
"FlatGFA File Size Avg": {
86+
"File": {"value": f"{round(benchmark(), 2)} KB"},
87+
}
88+
}
89+
90+
json.dump(bencher_json, sys.stdout)

bench/latency_benchmark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def benchmark(test_file, num_iter):
99
for i in range(num_iter):
1010
start_time = time.time()
1111
with open(os.devnull, "w") as devnull:
12-
subprocess.run(["fgfa", "-I", test_file, "extract", "-n", "3", "-c", "3"], stdout=devnull,
12+
subprocess.run(["target/release/fgfa", "-I", test_file, "extract", "-n", "3", "-c", "3"], stdout=devnull,
1313
stderr=devnull,
1414
check=True)
1515
end_time = time.time()

bench/latency_benchmark_web.py

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import sys
2+
import os
3+
import json
4+
import subprocess
5+
from pathlib import Path
6+
import time
7+
import tomllib
8+
import gzip
9+
import shutil
10+
11+
with open("bench/graphs.toml", "rb") as f:
12+
toml_graphs = tomllib.load(f)
13+
14+
hprc_dict = dict(toml_graphs["hprc"])
15+
16+
test_dict = dict(toml_graphs["test"])
17+
18+
gont_dict = dict(toml_graphs["1000gont"])
19+
20+
mini_files = [test_dict["lpa"], test_dict["chr6c4"], hprc_dict["chrM"]]
21+
22+
med_files = [hprc_dict["chr20"], hprc_dict["chrX"], gont_dict["chr16"]]
23+
24+
big_files = [hprc_dict["chrY"], hprc_dict["chr1"], hprc_dict["chr10"]]
25+
26+
results = "filesize_benchmark.txt"
27+
28+
def download_file(target_name, web_file):
29+
gzipped = False
30+
temp_name = ""
31+
if "gfa.gz" in web_file:
32+
gzipped = True
33+
if gzipped:
34+
temp_name = f"{target_name}.gz"
35+
36+
if not Path(target_name).exists():
37+
if gzipped:
38+
subprocess.run(["curl", "-o", temp_name, web_file],
39+
check = True)
40+
with gzip.open(temp_name, "rb") as f_in:
41+
with open(target_name, "wb") as f_out:
42+
shutil.copyfileobj(f_in, f_out)
43+
subprocess.run(["rm", "-rf", temp_name], check = True)
44+
else:
45+
subprocess.run(["curl", "-o", target_name, web_file],
46+
check = True)
47+
48+
def benchmark():
49+
test_config = ""
50+
test_cond = ""
51+
num_iter = 0
52+
if len(sys.argv) >= 2:
53+
test_config = sys.argv[1] #Can be either "mini", "med", or "big"
54+
else:
55+
raise ValueError("No arguments provided")
56+
57+
if len(sys.argv) >= 3:
58+
test_cond = sys.argv[2] # Can be "del", or not provided
59+
60+
test_files = []
61+
if test_config == "mini":
62+
test_files = mini_files
63+
num_iter = 10
64+
elif test_config == "med":
65+
test_files = med_files
66+
num_iter = 5
67+
elif test_config == "big":
68+
test_files = big_files
69+
num_iter = 2
70+
else:
71+
raise ValueError("Incorrect test config provided")
72+
73+
size_bytes_avg = 0
74+
i = 0
75+
total_time = 0.0
76+
for file in test_files:
77+
test_file_name = f"tests/{test_config}_{i}.gfa"
78+
download_file(test_file_name, file)
79+
for _ in range(num_iter):
80+
start_time = time.time()
81+
with open(os.devnull, "w") as devnull:
82+
subprocess.run(["target/release/fgfa", "-I", test_file_name, "extract", "-n", "3", "-c", "3"], stdout=devnull,
83+
stderr=devnull,
84+
check=True)
85+
end_time = time.time()
86+
total_time += (end_time - start_time) * 1000
87+
subprocess.run(["rm", "-rf", results], check = True)
88+
if test_cond == "del":
89+
subprocess.run(["rm", "-rf", test_file_name], check = True)
90+
i += 1
91+
return total_time / (num_iter * len(test_files))
92+
93+
bencher_json = {
94+
"FlatGFA File Size Avg": {
95+
"File": {"value": f"{round(benchmark(), 2)} ms"},
96+
}
97+
}
98+
99+
json.dump(bencher_json, sys.stdout)

0 commit comments

Comments
 (0)