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>
35 #define ITERATIONS 5000000
36 #define BLOCK_SIZE (10 * 1000) // fits in cache
40 #define AMPLITUDE 2.444444444
44 timeval_to_double (const struct timeval *tv)
46 return (double) tv->tv_sec + (double) tv->tv_usec * 1e-6;
51 benchmark (void test (float *x, const float *y), const char *implementation_name)
53 #ifdef HAVE_SYS_RESOURCE_H
54 struct rusage rusage_start;
55 struct rusage rusage_stop;
60 float output[BLOCK_SIZE];
61 float input[BLOCK_SIZE];
64 memset(output, 0, BLOCK_SIZE*sizeof(float));
65 for (int i = 0; i<BLOCK_SIZE; i++)
68 // get starting CPU usage
69 #ifdef HAVE_SYS_RESOURCE_H
70 if (getrusage (RUSAGE_SELF, &rusage_start) < 0){
75 clock_start = (double) clock() * (1000000. / CLOCKS_PER_SEC);
81 // get ending CPU usage
83 #ifdef HAVE_SYS_RESOURCE_H
84 if (getrusage (RUSAGE_SELF, &rusage_stop) < 0){
92 timeval_to_double (&rusage_stop.ru_utime)
93 - timeval_to_double (&rusage_start.ru_utime);
96 timeval_to_double (&rusage_stop.ru_stime)
97 - timeval_to_double (&rusage_start.ru_stime);
99 double total = user + sys;
101 clock_end = (double) clock () * (1000000. / CLOCKS_PER_SEC);
102 double total = clock_end - clock_start;
105 printf ("%18s: cpu: %6.3f steps/sec: %10.3e\n",
106 implementation_name, total, ITERATIONS / total);
109 // ----------------------------------------------------------------
111 void basic_vco (float *output, const float *input)
115 for (int j = 0; j < ITERATIONS/BLOCK_SIZE; j++){
116 for (int i = 0; i < BLOCK_SIZE; i++){
117 output[i] = cos(phase) * AMPLITUDE;
118 phase += input[i] * K;
120 while (phase > 2 * M_PI)
123 while (phase < -2 * M_PI)
129 void native_vco (float *output, const float *input)
131 gr_vco<float,float> vco;
133 for (int j = 0; j < ITERATIONS/BLOCK_SIZE; j++){
134 vco.cos(output, input, BLOCK_SIZE, K, AMPLITUDE);
138 void fxpt_vco (float *output, const float *input)
142 for (int j = 0; j < ITERATIONS/BLOCK_SIZE; j++){
143 vco.cos(output, input, BLOCK_SIZE, K, AMPLITUDE);
147 // ----------------------------------------------------------------
149 void nop_fct (float *x, const float *y)
153 void nop_loop (float *x, const float *y)
155 for (int i = 0; i < ITERATIONS; i++){
161 main (int argc, char **argv)
163 benchmark (nop_loop, "nop loop");
164 benchmark (basic_vco, "basic vco");
165 benchmark (native_vco, "native vco");
166 benchmark (fxpt_vco, "fxpt vco");