-
Notifications
You must be signed in to change notification settings - Fork 1
/
performance_test_NTT.py
55 lines (51 loc) · 2.39 KB
/
performance_test_NTT.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
import RF
from RF_NTT import polynomial
from RF_NTT import polynomial_sum3_performance
from ete3 import Tree
import time
import os
import csv
import logging
logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.INFO)
def time_tree(newick):
tree = Tree(newick)
t0 = time.time()
sum3_dt = polynomial_sum3_performance(tree, tree.get_leaves().__len__() + 1)[1]
tf = time.time()
return tf - t0, sum3_dt
performance_test_directory = '/Users/maryam/Desktop/Research/RF_improvment/FinalCodes/Frank/RF-master/TreePerformanceTest/'
treeset_performances = {}
files = sorted(os.listdir(performance_test_directory))
logging.info("Filenames loaded.")
logging.info("Begin performance testing.")
time.sleep(0.1)
for i, filename in enumerate(files):
print("Scanning " + str(i) + " out of " + str(files.__len__()) + " files. [" + str(
((i + 1) / files.__len__()) * 100)[0:5] + "%]")
if filename.endswith(".tre"):
print("Running performance test on " + filename)
f = open(performance_test_directory + filename)
lines = f.read()
tree_name = filename[0:filename.find("_")]
if tree_name not in treeset_performances:
treeset_performances[tree_name] = [""], ["T_poly"], ["T_con"]
treeset_performances[tree_name][0].append("tree" + filename[filename.find("_") + 1:filename.find(".")])
dt, sum3_dt = time_tree(lines)
treeset_performances[tree_name][1].append(dt)
treeset_performances[tree_name][2].append(sum3_dt)
else:
logging.info("Skipping " + filename + " because is not a .tre file.")
logging.info("Finish performance test. Writing to file...")
for key in treeset_performances.keys():
labels = treeset_performances[key][0]
T_poly_times = treeset_performances[key][1]
T_con_times = treeset_performances[key][2]
new_filename = '/Users/maryam/Desktop/Research/RF_improvment/FinalCodes/Frank/RF-master/performance_results_NTT/M' + key[4:] + '.csv'
print('name=',new_filename)
logging.info("Writing to " + new_filename)
with open(new_filename, mode='w') as performance_file:
writer = csv.writer(performance_file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
writer.writerow(labels)
writer.writerow(T_poly_times)
writer.writerow(T_con_times)
logging.info("Finish writing results to files. Find results in " + os.getcwd() + "/performance_results")