1 '''
 2 Python script to plot C FFT/DFT performance data from file.
 3 John Bryan 2017
 4 Python 2.7.3
 5 '''
 6 
 7 
 8 import numpy as np
 9 import matplotlib.pyplot as plt
10 import warnings
11 np.set_printoptions(threshold = np.nan, precision = 3, suppress = 1)
12 warnings.filterwarnings("ignore")
13 
14 
15 def plot():
16     '''
17     plot data from file 
18     '''
19     number = 7
20     xvector = np.loadtxt('file.txt',  usecols = range(0, 2))
21     zmatrix = np.array(xvector)
22     uarray = np.zeros(number, dtype = int)
23     varray = np.zeros(number, dtype = int)
24     warray = np.zeros(number, dtype = int)
25     yarray = np.zeros(number, dtype = int)
26     tarray = np.zeros(number, dtype = int)
27     garray = np.zeros(number, dtype = int)
28     harray = np.zeros(number, dtype = int)
29     for i in range (0, number, 1):
30         uarray[i] = zmatrix[i][0]
31         varray[i] = zmatrix[i][1]
32     for i in range (0, number, 1):
33         index = int(number+i)
34         warray[i] = zmatrix[index][1]
35     for i in range (0, number, 1):
36         index = int((2*number)+i)
37         yarray[i] = zmatrix[index][1]
38     for i in range (0, number, 1):
39         index = int((3*number)+i)
40         tarray[i] = zmatrix[index][1]
41     garray = np.linspace(50, 5200, 200)
42     harray = (garray/2)*np.log2(garray)
43     karray = garray*garray
44     plt.figure(figsize = (7, 5))
45     plt.rc("font", size = 9)
46     plt.loglog(uarray, yarray, 'g*', basex = 2, basey = 10, \
47                label = 'non-fft dft')
48     plt.loglog(uarray, varray, 'rs', basex = 2, basey = 10, \
49                label = 'recursion fft')
50     plt.loglog(uarray, warray, 'bD', basex = 2, basey = 10, label = 'iteration fft')
51     plt.loglog(uarray, tarray, 'mo', basex = 2, basey = 10, label = 'fftw3')
52     plt.loglog(garray, karray, 'g--', basex = 2, basey = 10, label = r'$N^2$')
53     plt.loglog(garray, harray, 'b', basex = 2, basey = 10, \
54                label = r'$\frac{N}{2}\log_2N$')
55     plt.legend(loc = 2)
56     plt.grid()
57     plt.xlim([50, 5200])
58     plt.ylabel("complex multiplication time units")
59     plt.xlabel("sequence length")
60     plt.title("Performance vs Sequence Length")
61     plt.savefig('tvl.png',  bbox_inches = 'tight')
62     plt.show()
63     return None
64 
65 plot()