3 * Copyright 2002,2004,2005 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_vco.h>
34 #define ITERATIONS 5000000
35 #define BLOCK_SIZE (10 * 1000) // fits in cache
39 #define AMPLITUDE 2.444444444
43 timeval_to_double (const struct timeval *tv)
45 return (double) tv->tv_sec + (double) tv->tv_usec * 1e-6;
50 benchmark (void test (float *x, const float *y), const char *implementation_name)
52 #ifdef HAVE_SYS_RESOURCE_H
53 struct rusage rusage_start;
54 struct rusage rusage_stop;
59 float output[BLOCK_SIZE];
60 float input[BLOCK_SIZE];
63 memset(output, 0, BLOCK_SIZE*sizeof(float));
64 for (int i = 0; i<BLOCK_SIZE; i++)
67 // get starting CPU usage
68 #ifdef HAVE_SYS_RESOURCE_H
69 if (getrusage (RUSAGE_SELF, &rusage_start) < 0){
74 clock_start = (double) clock() * (1000000. / CLOCKS_PER_SEC);
80 // get ending CPU usage
82 #ifdef HAVE_SYS_RESOURCE_H
83 if (getrusage (RUSAGE_SELF, &rusage_stop) < 0){
91 timeval_to_double (&rusage_stop.ru_utime)
92 - timeval_to_double (&rusage_start.ru_utime);
95 timeval_to_double (&rusage_stop.ru_stime)
96 - timeval_to_double (&rusage_start.ru_stime);
98 double total = user + sys;
100 clock_end = (double) clock () * (1000000. / CLOCKS_PER_SEC);
101 double total = clock_end - clock_start;
104 printf ("%18s: cpu: %6.3f steps/sec: %10.3e\n",
105 implementation_name, total, ITERATIONS / total);
108 // ----------------------------------------------------------------
110 void basic_vco (float *output, const float *input)
114 for (int j = 0; j < ITERATIONS/BLOCK_SIZE; j++){
115 for (int i = 0; i < BLOCK_SIZE; i++){
116 output[i] = cos(phase) * AMPLITUDE;
117 phase += input[i] * K;
119 while (phase > 2 * M_PI)
122 while (phase < -2 * M_PI)
128 void native_vco (float *output, const float *input)
130 gr_vco<float,float> vco;
132 for (int j = 0; j < ITERATIONS/BLOCK_SIZE; j++){
133 vco.cos(output, input, BLOCK_SIZE, K, AMPLITUDE);
137 void fxpt_vco (float *output, const float *input)
141 for (int j = 0; j < ITERATIONS/BLOCK_SIZE; j++){
142 vco.cos(output, input, BLOCK_SIZE, K, AMPLITUDE);
146 // ----------------------------------------------------------------
148 void nop_fct (float *x, const float *y)
152 void nop_loop (float *x, const float *y)
154 for (int i = 0; i < ITERATIONS; i++){
160 main (int argc, char **argv)
162 benchmark (nop_loop, "nop loop");
163 benchmark (basic_vco, "basic vco");
164 benchmark (native_vco, "native vco");
165 benchmark (fxpt_vco, "fxpt vco");