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 2, 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>
34 #define ITERATIONS 20000000
35 #define BLOCK_SIZE (10 * 1000) // fits in cache
40 timeval_to_double (const struct timeval *tv)
42 return (double) tv->tv_sec + (double) tv->tv_usec * 1e-6;
47 benchmark (void test (float *x, float *y), const char *implementation_name)
49 #ifdef HAVE_SYS_RESOURCE_H
50 struct rusage rusage_start;
51 struct rusage rusage_stop;
56 float output[2*BLOCK_SIZE];
57 float *x = &output[0], *y = &output[BLOCK_SIZE];
60 memset(output, 0, 2*BLOCK_SIZE*sizeof(float));
62 // get starting CPU usage
63 #ifdef HAVE_SYS_RESOURCE_H
64 if (getrusage (RUSAGE_SELF, &rusage_start) < 0){
69 clock_start = (double) clock() * (1000000. / CLOCKS_PER_SEC);
75 // get ending CPU usage
77 #ifdef HAVE_SYS_RESOURCE_H
78 if (getrusage (RUSAGE_SELF, &rusage_stop) < 0){
86 timeval_to_double (&rusage_stop.ru_utime)
87 - timeval_to_double (&rusage_start.ru_utime);
90 timeval_to_double (&rusage_stop.ru_stime)
91 - timeval_to_double (&rusage_start.ru_stime);
93 double total = user + sys;
95 clock_end = (double) clock () * (1000000. / CLOCKS_PER_SEC);
96 double total = clock_end - clock_start;
99 printf ("%18s: cpu: %6.3f steps/sec: %10.3e\n",
100 implementation_name, total, ITERATIONS / total);
103 // ----------------------------------------------------------------
104 // Don't compare the _vec with other functions since memory store's
107 void basic_sincos_vec (float *x, float *y)
109 gr_nco<float,float> nco;
111 nco.set_freq (2 * M_PI / FREQ);
113 for (int i = 0; i < ITERATIONS/BLOCK_SIZE; i++){
114 for (int j = 0; j < BLOCK_SIZE; j++){
115 nco.sincos (&x[2*j+1], &x[2*j]);
121 void native_sincos_vec (float *x, float *y)
123 gr_nco<float,float> nco;
125 nco.set_freq (2 * M_PI / FREQ);
127 for (int i = 0; i < ITERATIONS/BLOCK_SIZE; i++){
128 nco.sincos ((gr_complex*)x, BLOCK_SIZE);
132 void fxpt_sincos_vec (float *x, float *y)
136 nco.set_freq (2 * M_PI / FREQ);
138 for (int i = 0; i < ITERATIONS/BLOCK_SIZE; i++){
139 nco.sincos ((gr_complex*)x, BLOCK_SIZE);
143 // ----------------------------------------------------------------
145 void native_sincos (float *x, float *y)
147 gr_nco<float,float> nco;
149 nco.set_freq (2 * M_PI / FREQ);
151 for (int i = 0; i < ITERATIONS; i++){
157 void fxpt_sincos (float *x, float *y)
161 nco.set_freq (2 * M_PI / FREQ);
163 for (int i = 0; i < ITERATIONS; i++){
169 // ----------------------------------------------------------------
171 void native_sin (float *x, float *y)
173 gr_nco<float,float> nco;
175 nco.set_freq (2 * M_PI / FREQ);
177 for (int i = 0; i < ITERATIONS; i++){
183 void fxpt_sin (float *x, float *y)
187 nco.set_freq (2 * M_PI / FREQ);
189 for (int i = 0; i < ITERATIONS; i++){
195 // ----------------------------------------------------------------
197 void nop_fct (float *x, float *y)
201 void nop_loop (float *x, float *y)
203 for (int i = 0; i < ITERATIONS; i++){
209 main (int argc, char **argv)
211 benchmark (nop_loop, "nop loop");
212 benchmark (native_sin, "native sine");
213 benchmark (fxpt_sin, "fxpt sine");
214 benchmark (native_sincos, "native sin/cos");
215 benchmark (fxpt_sincos, "fxpt sin/cos");
216 benchmark (basic_sincos_vec, "basic sin/cos vec");
217 benchmark (native_sincos_vec, "native sin/cos vec");
218 benchmark (fxpt_sincos_vec, "fxpt sin/cos vec");