4
4
import csv
5
5
import re
6
6
7
+
7
8
def parse_file (file_path ):
8
9
data = {}
9
10
current_dataset = None
10
11
current_algorithm = None
11
12
current_size = None
12
13
13
- with open (file_path , 'r' ) as file :
14
+ with open (file_path , "r" ) as file :
14
15
for line in file :
15
16
line = line .strip ()
16
17
17
- if line .startswith (' dataset:' ):
18
- current_dataset = line .split (':' )[1 ].strip ()
19
- elif line .startswith (' algorithm:' ):
20
- current_algorithm = line .split (':' )[1 ].strip ()
21
- elif line .startswith (' size:' ):
22
- current_size = int (line .split (':' )[1 ].strip ())
23
- elif line .startswith ('|' ):
24
- fields = line .split ('|' )[1 :]
18
+ if line .startswith (" dataset:" ):
19
+ current_dataset = line .split (":" )[1 ].strip ()
20
+ elif line .startswith (" algorithm:" ):
21
+ current_algorithm = line .split (":" )[1 ].strip ()
22
+ elif line .startswith (" size:" ):
23
+ current_size = int (line .split (":" )[1 ].strip ())
24
+ elif line .startswith ("|" ):
25
+ fields = line .split ("|" )[1 :]
25
26
if len (fields ) >= 5 :
26
27
try :
27
28
ns_op = float (fields [0 ].strip ())
@@ -34,44 +35,57 @@ def parse_file(file_path):
34
35
data [current_dataset ] = {}
35
36
if current_algorithm not in data [current_dataset ]:
36
37
data [current_dataset ][current_algorithm ] = {
37
- ' size' : current_size
38
+ " size" : current_size
38
39
}
39
40
40
41
if "chained" in key_gen_type :
41
- data [current_dataset ][current_algorithm ]['ns_op_chained' ] = ns_op
42
+ data [current_dataset ][current_algorithm ][
43
+ "ns_op_chained"
44
+ ] = ns_op
42
45
elif "independent" in key_gen_type :
43
- data [current_dataset ][current_algorithm ]['ns_op_independent' ] = ns_op
44
-
46
+ data [current_dataset ][current_algorithm ][
47
+ "ns_op_independent"
48
+ ] = ns_op
45
49
46
50
return data
47
51
48
52
49
53
def generate_csv_tables (data , output_prefix ):
50
54
datasets = list (data .keys ())
51
- algorithms = sorted (set (algo for dataset in data .values () for algo in dataset .keys ()))
55
+ algorithms = sorted (
56
+ set (algo for dataset in data .values () for algo in dataset .keys ())
57
+ )
52
58
53
59
# Table 1: Chained Algorithm Performance (ns/op) vs Dataset
54
- with open (f' { output_prefix } _chained_performance.csv' , 'w' , newline = '' ) as file :
60
+ with open (f" { output_prefix } _chained_performance.csv" , "w" , newline = "" ) as file :
55
61
writer = csv .writer (file )
56
- writer .writerow ([' Dataset' ] + algorithms )
62
+ writer .writerow ([" Dataset" ] + algorithms )
57
63
for dataset in datasets :
58
- row = [dataset ] + [data [dataset ].get (algo , {}).get ('ns_op_chained' , '' ) for algo in algorithms ]
64
+ row = [dataset ] + [
65
+ data [dataset ].get (algo , {}).get ("ns_op_chained" , "" )
66
+ for algo in algorithms
67
+ ]
59
68
writer .writerow (row )
60
69
61
70
# Table 2: Independent Algorithm Performance (ns/op) vs Dataset
62
- with open (f' { output_prefix } _independent_performance.csv' , 'w' , newline = '' ) as file :
71
+ with open (f" { output_prefix } _independent_performance.csv" , "w" , newline = "" ) as file :
63
72
writer = csv .writer (file )
64
- writer .writerow ([' Dataset' ] + algorithms )
73
+ writer .writerow ([" Dataset" ] + algorithms )
65
74
for dataset in datasets :
66
- row = [dataset ] + [data [dataset ].get (algo , {}).get ('ns_op_independent' , '' ) for algo in algorithms ]
75
+ row = [dataset ] + [
76
+ data [dataset ].get (algo , {}).get ("ns_op_independent" , "" )
77
+ for algo in algorithms
78
+ ]
67
79
writer .writerow (row )
68
80
69
81
# Table 3: Algorithm Size (bytes) vs Dataset
70
- with open (f' { output_prefix } _algorithm_size.csv' , 'w' , newline = '' ) as file :
82
+ with open (f" { output_prefix } _algorithm_size.csv" , "w" , newline = "" ) as file :
71
83
writer = csv .writer (file )
72
- writer .writerow ([' Dataset' ] + algorithms )
84
+ writer .writerow ([" Dataset" ] + algorithms )
73
85
for dataset in datasets :
74
- row = [dataset ] + [data [dataset ].get (algo , {}).get ('size' , '' ) for algo in algorithms ]
86
+ row = [dataset ] + [
87
+ data [dataset ].get (algo , {}).get ("size" , "" ) for algo in algorithms
88
+ ]
75
89
writer .writerow (row )
76
90
77
91
0 commit comments