/* -*- c++ -*- */ /* * Copyright 2002,2004,2005 Free Software Foundation, Inc. * * This file is part of GNU Radio * * GNU Radio is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3, or (at your option) * any later version. * * GNU Radio is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with GNU Radio; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #ifdef HAVE_SYS_RESOURCE_H #include #endif #include #include #include #include #define ITERATIONS 5000000 #define BLOCK_SIZE (10 * 1000) // fits in cache #define FREQ 5003.123 #define K 4.9999999 #define AMPLITUDE 2.444444444 static double timeval_to_double (const struct timeval *tv) { return (double) tv->tv_sec + (double) tv->tv_usec * 1e-6; } static void benchmark (void test (float *x, const float *y), const char *implementation_name) { #ifdef HAVE_SYS_RESOURCE_H struct rusage rusage_start; struct rusage rusage_stop; #else double clock_start; double clock_end; #endif float output[BLOCK_SIZE]; float input[BLOCK_SIZE]; // touch memory memset(output, 0, BLOCK_SIZE*sizeof(float)); for (int i = 0; i 2 * M_PI) phase -= 2 * M_PI; while (phase < -2 * M_PI) phase += 2 * M_PI; } } } void native_vco (float *output, const float *input) { gr_vco vco; for (int j = 0; j < ITERATIONS/BLOCK_SIZE; j++){ vco.cos(output, input, BLOCK_SIZE, K, AMPLITUDE); } } void fxpt_vco (float *output, const float *input) { gr_fxpt_vco vco; for (int j = 0; j < ITERATIONS/BLOCK_SIZE; j++){ vco.cos(output, input, BLOCK_SIZE, K, AMPLITUDE); } } // ---------------------------------------------------------------- void nop_fct (float *x, const float *y) { } void nop_loop (float *x, const float *y) { for (int i = 0; i < ITERATIONS; i++){ nop_fct (x, y); } } int main (int argc, char **argv) { benchmark (nop_loop, "nop loop"); benchmark (basic_vco, "basic vco"); benchmark (native_vco, "native vco"); benchmark (fxpt_vco, "fxpt vco"); }