From 5d69a524f81f234b3fbc41d49ba18d6f6886baba Mon Sep 17 00:00:00 2001 From: jcorgan Date: Thu, 3 Aug 2006 04:51:51 +0000 Subject: Houston, we have a trunk. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@3122 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/tests/benchmark_nco.cc | 219 +++++++++++++++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100644 gnuradio-core/src/tests/benchmark_nco.cc (limited to 'gnuradio-core/src/tests/benchmark_nco.cc') diff --git a/gnuradio-core/src/tests/benchmark_nco.cc b/gnuradio-core/src/tests/benchmark_nco.cc new file mode 100644 index 000000000..fb0fe687b --- /dev/null +++ b/gnuradio-core/src/tests/benchmark_nco.cc @@ -0,0 +1,219 @@ +/* -*- c++ -*- */ +/* + * Copyright 2002,2004 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 2, 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include +#include +#ifdef HAVE_SYS_RESOURCE_H +#include +#endif +#include +#include +#include + +#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_nco 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_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 fxpt_sincos_vec (float *x, float *y) +{ + gr_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_nco 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_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_nco 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_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"); +} -- cgit From 86f5c92427b3f4bb30536d76cf63c3fca388fb2f Mon Sep 17 00:00:00 2001 From: eb Date: Wed, 13 Sep 2006 21:30:04 +0000 Subject: Updated FSF address in all files. Fixes ticket:51 git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@3534 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/tests/benchmark_nco.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gnuradio-core/src/tests/benchmark_nco.cc') diff --git a/gnuradio-core/src/tests/benchmark_nco.cc b/gnuradio-core/src/tests/benchmark_nco.cc index fb0fe687b..1c787f3cb 100644 --- a/gnuradio-core/src/tests/benchmark_nco.cc +++ b/gnuradio-core/src/tests/benchmark_nco.cc @@ -16,8 +16,8 @@ * * 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H #include "config.h" -- cgit From 937b719d2e57d0497293d603da10cac2532346f6 Mon Sep 17 00:00:00 2001 From: eb Date: Sat, 21 Jul 2007 03:44:38 +0000 Subject: Updated license from GPL version 2 or later to GPL version 3 or later. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@6044 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/tests/benchmark_nco.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-core/src/tests/benchmark_nco.cc') diff --git a/gnuradio-core/src/tests/benchmark_nco.cc b/gnuradio-core/src/tests/benchmark_nco.cc index 1c787f3cb..961442fc9 100644 --- a/gnuradio-core/src/tests/benchmark_nco.cc +++ b/gnuradio-core/src/tests/benchmark_nco.cc @@ -6,7 +6,7 @@ * * 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 2, or (at your option) + * 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, -- cgit From 38ea3a576a20820e574c6cb37607aeafe07f34b4 Mon Sep 17 00:00:00 2001 From: eb Date: Wed, 30 Apr 2008 02:24:06 +0000 Subject: Tweaks for gcc 4.3 based on patch from Marek Mahut . git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8292 221aa14e-8319-0410-a670-987f0aec2ac5 --- gnuradio-core/src/tests/benchmark_nco.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'gnuradio-core/src/tests/benchmark_nco.cc') diff --git a/gnuradio-core/src/tests/benchmark_nco.cc b/gnuradio-core/src/tests/benchmark_nco.cc index 961442fc9..9c4eff346 100644 --- a/gnuradio-core/src/tests/benchmark_nco.cc +++ b/gnuradio-core/src/tests/benchmark_nco.cc @@ -30,6 +30,7 @@ #include #include #include +#include #define ITERATIONS 20000000 #define BLOCK_SIZE (10 * 1000) // fits in cache -- cgit From f919f9dcbb54a08e6e26d6c229ce92fb784fa1b2 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Fri, 13 Apr 2012 18:36:53 -0400 Subject: Removed whitespace and added dtools/bin/remove-whitespace as a tool to do this in the future. The sed script was provided by Moritz Fischer. --- gnuradio-core/src/tests/benchmark_nco.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gnuradio-core/src/tests/benchmark_nco.cc') diff --git a/gnuradio-core/src/tests/benchmark_nco.cc b/gnuradio-core/src/tests/benchmark_nco.cc index 9c4eff346..20d53e410 100644 --- a/gnuradio-core/src/tests/benchmark_nco.cc +++ b/gnuradio-core/src/tests/benchmark_nco.cc @@ -124,7 +124,7 @@ void native_sincos_vec (float *x, float *y) gr_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); } @@ -133,9 +133,9 @@ void native_sincos_vec (float *x, float *y) void fxpt_sincos_vec (float *x, float *y) { gr_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); } -- cgit