3 * Copyright 2002,2004 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
27 #ifdef HAVE_SYS_RESOURCE_H
28 #include <sys/resource.h>
32 #include <gr_fxpt_nco.h>
35 #define ITERATIONS 20000000
36 #define BLOCK_SIZE (10 * 1000) // fits in cache
41 timeval_to_double (const struct timeval *tv)
43 return (double) tv->tv_sec + (double) tv->tv_usec * 1e-6;
48 benchmark (void test (float *x, float *y), const char *implementation_name)
50 #ifdef HAVE_SYS_RESOURCE_H
51 struct rusage rusage_start;
52 struct rusage rusage_stop;
57 float output[2*BLOCK_SIZE];
58 float *x = &output[0], *y = &output[BLOCK_SIZE];
61 memset(output, 0, 2*BLOCK_SIZE*sizeof(float));
63 // get starting CPU usage
64 #ifdef HAVE_SYS_RESOURCE_H
65 if (getrusage (RUSAGE_SELF, &rusage_start) < 0){
70 clock_start = (double) clock() * (1000000. / CLOCKS_PER_SEC);
76 // get ending CPU usage
78 #ifdef HAVE_SYS_RESOURCE_H
79 if (getrusage (RUSAGE_SELF, &rusage_stop) < 0){
87 timeval_to_double (&rusage_stop.ru_utime)
88 - timeval_to_double (&rusage_start.ru_utime);
91 timeval_to_double (&rusage_stop.ru_stime)
92 - timeval_to_double (&rusage_start.ru_stime);
94 double total = user + sys;
96 clock_end = (double) clock () * (1000000. / CLOCKS_PER_SEC);
97 double total = clock_end - clock_start;
100 printf ("%18s: cpu: %6.3f steps/sec: %10.3e\n",
101 implementation_name, total, ITERATIONS / total);
104 // ----------------------------------------------------------------
105 // Don't compare the _vec with other functions since memory store's
108 void basic_sincos_vec (float *x, float *y)
110 gr_nco<float,float> nco;
112 nco.set_freq (2 * M_PI / FREQ);
114 for (int i = 0; i < ITERATIONS/BLOCK_SIZE; i++){
115 for (int j = 0; j < BLOCK_SIZE; j++){
116 nco.sincos (&x[2*j+1], &x[2*j]);
122 void native_sincos_vec (float *x, float *y)
124 gr_nco<float,float> nco;
126 nco.set_freq (2 * M_PI / FREQ);
128 for (int i = 0; i < ITERATIONS/BLOCK_SIZE; i++){
129 nco.sincos ((gr_complex*)x, BLOCK_SIZE);
133 void fxpt_sincos_vec (float *x, float *y)
137 nco.set_freq (2 * M_PI / FREQ);
139 for (int i = 0; i < ITERATIONS/BLOCK_SIZE; i++){
140 nco.sincos ((gr_complex*)x, BLOCK_SIZE);
144 // ----------------------------------------------------------------
146 void native_sincos (float *x, float *y)
148 gr_nco<float,float> nco;
150 nco.set_freq (2 * M_PI / FREQ);
152 for (int i = 0; i < ITERATIONS; i++){
158 void fxpt_sincos (float *x, float *y)
162 nco.set_freq (2 * M_PI / FREQ);
164 for (int i = 0; i < ITERATIONS; i++){
170 // ----------------------------------------------------------------
172 void native_sin (float *x, float *y)
174 gr_nco<float,float> nco;
176 nco.set_freq (2 * M_PI / FREQ);
178 for (int i = 0; i < ITERATIONS; i++){
184 void fxpt_sin (float *x, float *y)
188 nco.set_freq (2 * M_PI / FREQ);
190 for (int i = 0; i < ITERATIONS; i++){
196 // ----------------------------------------------------------------
198 void nop_fct (float *x, float *y)
202 void nop_loop (float *x, float *y)
204 for (int i = 0; i < ITERATIONS; i++){
210 main (int argc, char **argv)
212 benchmark (nop_loop, "nop loop");
213 benchmark (native_sin, "native sine");
214 benchmark (fxpt_sin, "fxpt sine");
215 benchmark (native_sincos, "native sin/cos");
216 benchmark (fxpt_sincos, "fxpt sin/cos");
217 benchmark (basic_sincos_vec, "basic sin/cos vec");
218 benchmark (native_sincos_vec, "native sin/cos vec");
219 benchmark (fxpt_sincos_vec, "fxpt sin/cos vec");