3 * Copyright 2002 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>
31 #include <gr_fir_util.h>
32 #include <gr_fir_ccf.h>
35 #define TOTAL_TEST_SIZE (40 * 1000 * 1000L)
37 #define BLOCK_SIZE (50 * 1000) /* fits in cache */
39 #if ((TOTAL_TEST_SIZE % BLOCK_SIZE) != 0)
40 #error "TOTAL_TEST_SIZE % BLOCK_SIZE must equal 0"
43 typedef gr_fir_ccf* (*fir_maker_t)(const std::vector<float> &taps);
44 typedef gr_fir_ccf filter_t;
48 timeval_to_double (const struct timeval *tv)
50 return (double) tv->tv_sec + (double) tv->tv_usec * 1e-6;
55 benchmark (fir_maker_t filter_maker, const char *implementation_name)
59 gr_complex input[BLOCK_SIZE + NTAPS];
62 #ifdef HAVE_SYS_RESOURCE_H
63 struct rusage rusage_start;
64 struct rusage rusage_stop;
70 // setup coefficients and input data
72 for (i = 0; i < NTAPS; i++)
73 coeffs[i] = random() - RANDOM_MAX/2;
75 for (i = 0; i < BLOCK_SIZE + NTAPS; i++)
76 input[i] = gr_complex(random() - RANDOM_MAX/2, random() - RANDOM_MAX/2);
78 std::vector<float> taps (&coeffs[0], &coeffs[NTAPS]);
79 filter_t *f = filter_maker (taps);
81 // get starting CPU usage
83 #ifdef HAVE_SYS_RESOURCE_H
84 if (getrusage (RUSAGE_SELF, &rusage_start) < 0){
89 clock_start= (double) clock() * (1000000. / CLOCKS_PER_SEC);
94 for (n = 0; n < TOTAL_TEST_SIZE; n += BLOCK_SIZE){
96 for (j = 0; j < BLOCK_SIZE; j++){
97 result = f->filter (&input[j]);
101 // get ending CPU usage
103 #ifdef HAVE_SYS_RESOURCE_H
104 if (getrusage (RUSAGE_SELF, &rusage_stop) < 0){
105 perror ("getrusage");
112 timeval_to_double (&rusage_stop.ru_utime)
113 - timeval_to_double (&rusage_start.ru_utime);
116 timeval_to_double (&rusage_stop.ru_stime)
117 - timeval_to_double (&rusage_start.ru_stime);
119 double total = user + sys;
121 clock_end= (double) clock() * (1000000. / CLOCKS_PER_SEC);
122 double total = clock_end - clock_start;
125 double macs = NTAPS * (double) TOTAL_TEST_SIZE;
127 printf ("%10s: taps: %4d input: %4g cpu: %6.3f taps/sec: %10.4g \n",
128 implementation_name, NTAPS, (double) TOTAL_TEST_SIZE, total, macs / total);
136 std::vector<gr_fir_ccf_info> info;
137 gr_fir_util::get_gr_fir_ccf_info (&info); // get all known CCF implementations
139 for (std::vector<gr_fir_ccf_info>::iterator p = info.begin ();
142 benchmark (p->create, p->name);
147 main (int argc, char **argv)