9
9
10
10
plt .style .use ("fivethirtyeight" )
11
11
12
+
13
+ SYMBOLS = {
14
+ 'customary' : ('B' , 'K' , 'M' , 'G' , 'T' , 'P' , 'E' , 'Z' , 'Y' ),
15
+ 'customary_ext' : ('byte' , 'kilo' , 'mega' , 'giga' , 'tera' , 'peta' , 'exa' ,
16
+ 'zetta' , 'iotta' ),
17
+ 'iec' : ('Bi' , 'Ki' , 'Mi' , 'Gi' , 'Ti' , 'Pi' , 'Ei' , 'Zi' , 'Yi' ),
18
+ 'iec_ext' : ('byte' , 'kibi' , 'mebi' , 'gibi' , 'tebi' , 'pebi' , 'exbi' ,
19
+ 'zebi' , 'yobi' ),
20
+ }
21
+
22
+
12
23
def read_file (filepath : str ) -> list [int ]:
13
24
y = []
14
25
@@ -21,12 +32,12 @@ def read_file(filepath: str) -> list[int]:
21
32
22
33
23
34
def get_figure_of_interest (vals : list [int ]) -> float :
24
- return np .mean (vals )
35
+ return np .median (vals )
25
36
26
37
27
38
def build_and_clean_data (root_benchmark_dir : str , * names ) -> defaultdict [str , list ]:
28
39
libs = ("rustfft" , "phastft" )
29
- n_range = range (4 , 27 )
40
+ n_range = range (12 , 30 )
30
41
31
42
data = defaultdict (list )
32
43
@@ -39,31 +50,56 @@ def build_and_clean_data(root_benchmark_dir: str, *names) -> defaultdict[str, li
39
50
return data
40
51
41
52
def plot_lines (data : defaultdict [str , list ]) -> None :
42
- index = list ( range (4 , 27 ))
53
+ index = [ bytes2human ( 2 ** n * ( 128 / 8 )) for n in range (12 , 30 )]
43
54
plt .figure ()
44
55
45
- print (len (data ["phastft" ]))
56
+ y0 = np .asarray (data ["phastft" ])
57
+ y1 = np .asarray (data ["rustfft" ])
58
+ y0 = y1 / y0
46
59
47
60
df = pd .DataFrame (
48
61
{
49
- "PhastFT" : data [ "phastft" ] ,
50
- "RustFFT" : data [ "rustfft" ] ,
62
+ "PhastFT" : y0 ,
63
+ "RustFFT" : np . ones ( len ( index )) ,
51
64
},
52
65
index = index ,
53
66
)
54
67
55
68
df .plot (kind = 'bar' , linewidth = 3 , rot = 0 )
56
- plt .xticks (fontsize = 8 )
57
- plt .xlabel ("size" )
58
- plt .ylabel ("time (us)" )
59
- plt .yscale ("log" )
60
- plt .show ()
61
- # plt.tight_layout(pad=0.0)
62
- # plt.savefig("benchmarks_bar_plot.png", dpi=600)
69
+
70
+ plt .xticks (fontsize = 9 , rotation = - 45 )
71
+ plt .yticks (fontsize = 9 )
72
+ plt .xlabel ("size of input" )
73
+ plt .ylabel ("speedup (relative to RustFFT)" )
74
+ plt .legend (loc = 'best' )
75
+ plt .tight_layout ()
76
+ plt .savefig ("benchmarks_bar_plot.png" , dpi = 600 )
77
+
78
+
79
+ # Source: https://stackoverflow.com/a/1094933
80
+ def bytes2human (n , format = '%(value).1f %(symbol)s' , symbols = 'customary' ):
81
+ """
82
+ Convert n bytes into a human-readable string based on format.
83
+ symbols can be either "customary", "customary_ext", "iec" or "iec_ext",
84
+ see: https://goo.gl/kTQMs
85
+ """
86
+ n = int (n )
87
+ if n < 0 :
88
+ raise ValueError ("n < 0" )
89
+ symbols = SYMBOLS [symbols ]
90
+ prefix = {}
91
+ for i , s in enumerate (symbols [1 :]):
92
+ prefix [s ] = 1 << (i + 1 )* 10
93
+ for symbol in reversed (symbols [1 :]):
94
+ if n >= prefix [symbol ]:
95
+ value = float (n ) / prefix [symbol ]
96
+ return format % locals ()
97
+ return format % dict (symbol = symbols [0 ], value = n )
98
+
63
99
64
100
65
101
if __name__ == "__main__" :
66
102
# y = read_file("benchmark-data.2024.02.02.11-02-07/phastft/size_16")
67
- data = build_and_clean_data ("benchmark-data.2024.02.02.11-27-33 " )
68
- print (data )
69
- # plot_lines(data)
103
+ data = build_and_clean_data ("benchmark-data.2024.02.02.11-43-10 " )
104
+ # print(data)
105
+ plot_lines (data )
0 commit comments