diff options
Diffstat (limited to 'gr-blocks/tests')
-rw-r--r-- | gr-blocks/tests/CMakeLists.txt | 56 | ||||
-rw-r--r-- | gr-blocks/tests/benchmark_nco.cc | 225 | ||||
-rw-r--r-- | gr-blocks/tests/benchmark_vco.cc | 172 | ||||
-rw-r--r-- | gr-blocks/tests/nco_results | 48 |
4 files changed, 501 insertions, 0 deletions
diff --git a/gr-blocks/tests/CMakeLists.txt b/gr-blocks/tests/CMakeLists.txt new file mode 100644 index 000000000..8f7ba2f64 --- /dev/null +++ b/gr-blocks/tests/CMakeLists.txt @@ -0,0 +1,56 @@ +# Copyright 2010-2013 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. + +######################################################################## +include(GrMiscUtils) #check n def +GR_CHECK_HDR_N_DEF(sys/resource.h HAVE_SYS_RESOURCE_H) + +######################################################################## +# Setup the include and linker paths +######################################################################## +include_directories( + ${GR_BLOCKS_INCLUDE_DIRS} + ${GNURADIO_CORE_INCLUDE_DIRS} + ${GRUEL_INCLUDE_DIRS} + ${Boost_INCLUDE_DIRS} + ${CPPUNIT_INCLUDE_DIRS} +) + +link_directories( + ${Boost_LIBRARY_DIRS} + ${CPPUNIT_LIBRARY_DIRS} +) + +include_directories(${LOG4CXX_INCLUDE_DIRS}) +link_directories(${LOG4CXX_LIBRARY_DIRS}) + +######################################################################## +# Build benchmarks and non-registered tests +######################################################################## +set(tests_not_run #single source per test + benchmark_nco.cc + benchmark_vco.cc +) + +foreach(test_not_run_src ${tests_not_run}) + get_filename_component(name ${test_not_run_src} NAME_WE) + add_executable(${name} ${test_not_run_src}) + target_link_libraries(${name} test-gnuradio-core gnuradio-blocks) +endforeach(test_not_run_src) + diff --git a/gr-blocks/tests/benchmark_nco.cc b/gr-blocks/tests/benchmark_nco.cc new file mode 100644 index 000000000..4c2ed120d --- /dev/null +++ b/gr-blocks/tests/benchmark_nco.cc @@ -0,0 +1,225 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002,2004,2013 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 <stdio.h> +#include <stdlib.h> +#include <sys/time.h> + +#ifdef HAVE_SYS_RESOURCE_H +#include <sys/resource.h> +#endif + +#include <unistd.h> +#include <blocks/nco.h> +#include <blocks/fxpt_nco.h> +#include <string.h> + +#define ITERATIONS 20000000 +#define BLOCK_SIZE (10 * 1000) // fits in cache + +#define FREQ 5003.123 + +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, 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[2*BLOCK_SIZE]; + float *x = &output[0], *y = &output[BLOCK_SIZE]; + + // touch memory + memset(output, 0, 2*BLOCK_SIZE*sizeof(float)); + + // get starting CPU usage +#ifdef HAVE_SYS_RESOURCE_H + if(getrusage(RUSAGE_SELF, &rusage_start) < 0) { + perror("getrusage"); + exit(1); + } +#else + clock_start = (double)clock() * (1000000. / CLOCKS_PER_SEC); +#endif + // do the actual work + + test(x, y); + + // get ending CPU usage + +#ifdef HAVE_SYS_RESOURCE_H + if(getrusage(RUSAGE_SELF, &rusage_stop) < 0) { + perror("getrusage"); + exit(1); + } + + // compute results + + double user = + timeval_to_double(&rusage_stop.ru_utime) + - timeval_to_double(&rusage_start.ru_utime); + + double sys = + timeval_to_double(&rusage_stop.ru_stime) + - timeval_to_double(&rusage_start.ru_stime); + + double total = user + sys; +#else + clock_end = (double)clock() * (1000000. / CLOCKS_PER_SEC); + double total = clock_end - clock_start; +#endif + + printf("%18s: cpu: %6.3f steps/sec: %10.3e\n", + implementation_name, total, ITERATIONS / total); +} + +// ---------------------------------------------------------------- +// Don't compare the _vec with other functions since memory store's +// are involved. + +void basic_sincos_vec(float *x, float *y) +{ + gr::blocks::nco<float,float> nco; + + nco.set_freq(2 * M_PI / FREQ); + + for(int i = 0; i < ITERATIONS/BLOCK_SIZE; i++) { + for(int j = 0; j < BLOCK_SIZE; j++) { + nco.sincos(&x[2*j+1], &x[2*j]); + nco.step(); + } + } +} + +void native_sincos_vec(float *x, float *y) +{ + gr::blocks::nco<float,float> nco; + + nco.set_freq(2 * M_PI / FREQ); + + for(int i = 0; i < ITERATIONS/BLOCK_SIZE; i++) { + nco.sincos((gr_complex*)x, BLOCK_SIZE); + } +} + +void fxpt_sincos_vec(float *x, float *y) +{ + gr::blocks::fxpt_nco nco; + + nco.set_freq (2 * M_PI / FREQ); + + for(int i = 0; i < ITERATIONS/BLOCK_SIZE; i++) { + nco.sincos((gr_complex*)x, BLOCK_SIZE); + } +} + +// ---------------------------------------------------------------- + +void native_sincos(float *x, float *y) +{ + gr::blocks::nco<float,float> nco; + + nco.set_freq(2 * M_PI / FREQ); + + for(int i = 0; i < ITERATIONS; i++) { + nco.sincos(x, y); + nco.step(); + } +} + +void fxpt_sincos(float *x, float *y) +{ + gr::blocks::fxpt_nco nco; + + nco.set_freq(2 * M_PI / FREQ); + + for(int i = 0; i < ITERATIONS; i++) { + nco.sincos(x, y); + nco.step(); + } +} + +// ---------------------------------------------------------------- + +void native_sin(float *x, float *y) +{ + gr::blocks::nco<float,float> nco; + + nco.set_freq(2 * M_PI / FREQ); + + for(int i = 0; i < ITERATIONS; i++) { + *x = nco.sin(); + nco.step(); + } +} + +void fxpt_sin(float *x, float *y) +{ + gr::blocks::fxpt_nco nco; + + nco.set_freq(2 * M_PI / FREQ); + + for(int i = 0; i < ITERATIONS; i++) { + *x = nco.sin(); + nco.step(); + } +} + +// ---------------------------------------------------------------- + +void nop_fct(float *x, float *y) +{ +} + +void nop_loop(float *x, 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(native_sin, "native sine"); + benchmark(fxpt_sin, "fxpt sine"); + benchmark(native_sincos, "native sin/cos"); + benchmark(fxpt_sincos, "fxpt sin/cos"); + benchmark(basic_sincos_vec, "basic sin/cos vec"); + benchmark(native_sincos_vec, "native sin/cos vec"); + benchmark(fxpt_sincos_vec, "fxpt sin/cos vec"); +} diff --git a/gr-blocks/tests/benchmark_vco.cc b/gr-blocks/tests/benchmark_vco.cc new file mode 100644 index 000000000..955dc0805 --- /dev/null +++ b/gr-blocks/tests/benchmark_vco.cc @@ -0,0 +1,172 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002,2004,2005,2013 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 <stdio.h> +#include <stdlib.h> +#include <sys/time.h> + +#ifdef HAVE_SYS_RESOURCE_H +#include <sys/resource.h> +#endif + +#include <unistd.h> +#include <blocks/vco.h> +#include <blocks/fxpt_vco.h> +#include <string.h> + +#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<BLOCK_SIZE; i++) + input[i] = sin(double(i)); + + // get starting CPU usage +#ifdef HAVE_SYS_RESOURCE_H + if(getrusage (RUSAGE_SELF, &rusage_start) < 0) { + perror("getrusage"); + exit(1); + } +#else + clock_start = (double)clock() * (1000000. / CLOCKS_PER_SEC); +#endif + // do the actual work + + test(output, input); + + // get ending CPU usage + +#ifdef HAVE_SYS_RESOURCE_H + if(getrusage (RUSAGE_SELF, &rusage_stop) < 0) { + perror("getrusage"); + exit(1); + } + + // compute results + + double user = + timeval_to_double(&rusage_stop.ru_utime) + - timeval_to_double(&rusage_start.ru_utime); + + double sys = + timeval_to_double(&rusage_stop.ru_stime) + - timeval_to_double(&rusage_start.ru_stime); + + double total = user + sys; +#else + clock_end = (double)clock() * (1000000. / CLOCKS_PER_SEC); + double total = clock_end - clock_start; +#endif + + printf("%18s: cpu: %6.3f steps/sec: %10.3e\n", + implementation_name, total, ITERATIONS / total); +} + +// ---------------------------------------------------------------- + +void basic_vco(float *output, const float *input) +{ + double phase = 0; + + for(int j = 0; j < ITERATIONS/BLOCK_SIZE; j++) { + for(int i = 0; i < BLOCK_SIZE; i++) { + output[i] = cos(phase) * AMPLITUDE; + phase += input[i] * K; + + while(phase > 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::blocks::vco<float,float> 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::blocks::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"); +} diff --git a/gr-blocks/tests/nco_results b/gr-blocks/tests/nco_results new file mode 100644 index 000000000..5bdf5dd1c --- /dev/null +++ b/gr-blocks/tests/nco_results @@ -0,0 +1,48 @@ +================================================================ +These are on a 1.4 GHz Pentium M using g++ 3.4.1 +================================================================ + +Default compiler options -O2 + + nop loop: cpu: 0.015 steps/sec: 6.668e+08 + native sine: cpu: 0.900 steps/sec: 1.111e+07 + fxpt sine: cpu: 0.281 steps/sec: 3.559e+07 + native sin/cos: cpu: 1.138 steps/sec: 8.789e+06 + fxpt sin/cos: cpu: 0.550 steps/sec: 1.818e+07 + +-O2 -march=pentium-m -fomit-frame-pointer + + nop loop: cpu: 0.015 steps/sec: 6.668e+08 + native sine: cpu: 0.903 steps/sec: 1.108e+07 + fxpt sine: cpu: 0.271 steps/sec: 3.691e+07 + native sin/cos: cpu: 1.092 steps/sec: 9.159e+06 + fxpt sin/cos: cpu: 0.542 steps/sec: 1.845e+07 + +Inlined fxpt::sin & cos +-O2 -march=pentium-m -fomit-frame-pointer + + nop loop: cpu: 0.015 steps/sec: 6.668e+08 + native sine: cpu: 0.904 steps/sec: 1.106e+07 + fxpt sine: cpu: 0.187 steps/sec: 5.348e+07 + native sin/cos: cpu: 1.091 steps/sec: 9.167e+06 + fxpt sin/cos: cpu: 0.373 steps/sec: 2.681e+07 + +================================================================ +These are on a 1.5 GHz Athon MP 1800+ +================================================================ + +Default compiler options: -O2 + + nop loop: cpu: 0.013 steps/sec: 7.693e+08 + native sine: cpu: 0.733 steps/sec: 1.364e+07 + fxpt sine: cpu: 0.210 steps/sec: 4.763e+07 + native sin/cos: cpu: 1.183 steps/sec: 8.454e+06 + fxpt sin/cos: cpu: 0.420 steps/sec: 2.381e+07 + +-O2 -fomit-frame-pointer -march=athlon-mp + + nop loop: cpu: 0.013 steps/sec: 7.693e+08 + native sine: cpu: 0.679 steps/sec: 1.473e+07 + fxpt sine: cpu: 0.200 steps/sec: 5.001e+07 + native sin/cos: cpu: 1.147 steps/sec: 8.720e+06 + fxpt sin/cos: cpu: 0.444 steps/sec: 2.253e+07 |