Chris@0: /* Chris@0: ** Copyright (C) 2008-2011 Erik de Castro Lopo Chris@0: ** Chris@0: ** This program is free software; you can redistribute it and/or modify Chris@0: ** it under the terms of the GNU General Public License as published by Chris@0: ** the Free Software Foundation; either version 2 of the License, or Chris@0: ** (at your option) any later version. Chris@0: ** Chris@0: ** This program is distributed in the hope that it will be useful, Chris@0: ** but WITHOUT ANY WARRANTY; without even the implied warranty of Chris@0: ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Chris@0: ** GNU General Public License for more details. Chris@0: ** Chris@0: ** You should have received a copy of the GNU General Public License Chris@0: ** along with this program; if not, write to the Free Software Chris@0: ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. Chris@0: */ Chris@0: Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: Chris@0: #include Chris@0: Chris@0: #include "config.h" Chris@0: Chris@0: #include "util.h" Chris@0: #include "float_cast.h" Chris@0: Chris@0: #define BUFFER_LEN (1<<17) Chris@0: Chris@0: static float input [BUFFER_LEN] ; Chris@0: static float output [BUFFER_LEN] ; Chris@0: Chris@0: static long Chris@0: throughput_test (int converter, int channels, long best_throughput) Chris@0: { SRC_DATA src_data ; Chris@0: clock_t start_time, clock_time ; Chris@0: double duration ; Chris@0: long total_frames = 0, throughput ; Chris@0: int error ; Chris@0: Chris@0: printf (" %-30s %2d ", src_get_name (converter), channels) ; Chris@0: fflush (stdout) ; Chris@0: Chris@0: src_data.data_in = input ; Chris@0: src_data.input_frames = ARRAY_LEN (input) / channels ; Chris@0: Chris@0: src_data.data_out = output ; Chris@0: src_data.output_frames = ARRAY_LEN (output) / channels ; Chris@0: Chris@0: src_data.src_ratio = 0.99 ; Chris@0: Chris@0: sleep (2) ; Chris@0: Chris@0: start_time = clock () ; Chris@0: Chris@0: do Chris@0: { Chris@0: if ((error = src_simple (&src_data, converter, channels)) != 0) Chris@0: { puts (src_strerror (error)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: total_frames += src_data.output_frames_gen ; Chris@0: Chris@0: clock_time = clock () - start_time ; Chris@0: duration = (1.0 * clock_time) / CLOCKS_PER_SEC ; Chris@0: } Chris@0: while (duration < 5.0) ; Chris@0: Chris@0: if (src_data.input_frames_used != src_data.input_frames) Chris@0: { printf ("\n\nLine %d : input frames used %ld should be %ld\n", __LINE__, src_data.input_frames_used, src_data.input_frames) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: if (fabs (src_data.src_ratio * src_data.input_frames_used - src_data.output_frames_gen) > 2) Chris@0: { printf ("\n\nLine %d : input / output length mismatch.\n\n", __LINE__) ; Chris@0: printf (" input len : %d\n", ARRAY_LEN (input) / channels) ; Chris@0: printf (" output len : %ld (should be %g +/- 2)\n\n", src_data.output_frames_gen, Chris@0: floor (0.5 + src_data.src_ratio * src_data.input_frames_used)) ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: throughput = lrint (floor (total_frames / duration)) ; Chris@0: Chris@0: if (best_throughput == 0) Chris@0: { best_throughput = MAX (throughput, best_throughput) ; Chris@0: printf ("%5.2f %10ld\n", duration, throughput) ; Chris@0: } Chris@0: else Chris@0: { best_throughput = MAX (throughput, best_throughput) ; Chris@0: printf ("%5.2f %10ld %10ld\n", duration, throughput, best_throughput) ; Chris@0: } Chris@0: Chris@0: return best_throughput ; Chris@0: } /* throughput_test */ Chris@0: Chris@0: static void Chris@0: single_run (void) Chris@0: { const int max_channels = 10 ; Chris@0: int k ; Chris@0: Chris@0: printf ("\n CPU name : %s\n", get_cpu_name ()) ; Chris@0: Chris@0: puts ( Chris@0: "\n" Chris@0: " Converter Channels Duration Throughput\n" Chris@0: " ---------------------------------------------------------------------" Chris@0: ) ; Chris@0: Chris@0: for (k = 1 ; k <= max_channels / 2 ; k++) Chris@0: throughput_test (SRC_SINC_FASTEST, k, 0) ; Chris@0: Chris@0: puts ("") ; Chris@0: for (k = 1 ; k <= max_channels / 2 ; k++) Chris@0: throughput_test (SRC_SINC_MEDIUM_QUALITY, k, 0) ; Chris@0: Chris@0: puts ("") ; Chris@0: for (k = 1 ; k <= max_channels ; k++) Chris@0: throughput_test (SRC_SINC_BEST_QUALITY, k, 0) ; Chris@0: Chris@0: puts ("") ; Chris@0: return ; Chris@0: } /* single_run */ Chris@0: Chris@0: static void Chris@0: multi_run (int run_count) Chris@0: { int k, ch ; Chris@0: Chris@0: printf ("\n CPU name : %s\n", get_cpu_name ()) ; Chris@0: Chris@0: puts ( Chris@0: "\n" Chris@0: " Converter Channels Duration Throughput Best Throughput\n" Chris@0: " ----------------------------------------------------------------------------------------" Chris@0: ) ; Chris@0: Chris@0: for (ch = 1 ; ch <= 5 ; ch++) Chris@0: { long sinc_fastest = 0, sinc_medium = 0, sinc_best = 0 ; Chris@0: Chris@0: for (k = 0 ; k < run_count ; k++) Chris@0: { sinc_fastest = throughput_test (SRC_SINC_FASTEST, ch, sinc_fastest) ; Chris@0: sinc_medium = throughput_test (SRC_SINC_MEDIUM_QUALITY, ch, sinc_medium) ; Chris@0: sinc_best = throughput_test (SRC_SINC_BEST_QUALITY, ch, sinc_best) ; Chris@0: Chris@0: puts ("") ; Chris@0: Chris@0: /* Let the CPU cool down. We might be running on a laptop. */ Chris@0: sleep (10) ; Chris@0: } ; Chris@0: Chris@0: puts ( Chris@0: "\n" Chris@0: " Converter Best Throughput\n" Chris@0: " ------------------------------------------------" Chris@0: ) ; Chris@0: Chris@0: printf (" %-30s %10ld\n", src_get_name (SRC_SINC_FASTEST), sinc_fastest) ; Chris@0: printf (" %-30s %10ld\n", src_get_name (SRC_SINC_MEDIUM_QUALITY), sinc_medium) ; Chris@0: printf (" %-30s %10ld\n", src_get_name (SRC_SINC_BEST_QUALITY), sinc_best) ; Chris@0: } ; Chris@0: Chris@0: puts ("") ; Chris@0: } /* multi_run */ Chris@0: Chris@0: static void Chris@0: usage_exit (const char * argv0) Chris@0: { const char * cptr ; Chris@0: Chris@0: if ((cptr = strrchr (argv0, '/')) != NULL) Chris@0: argv0 = cptr ; Chris@0: Chris@0: printf ( Chris@0: "Usage :\n" Chris@0: " %s - Single run of the throughput test.\n" Chris@0: " %s --best-of N - Do N runs of test a print bext result.\n" Chris@0: "\n", Chris@0: argv0, argv0) ; Chris@0: Chris@0: exit (0) ; Chris@0: } /* usage_exit */ Chris@0: Chris@0: int Chris@0: main (int argc, char ** argv) Chris@0: { double freq ; Chris@0: Chris@0: memset (input, 0, sizeof (input)) ; Chris@0: freq = 0.01 ; Chris@0: gen_windowed_sines (1, &freq, 1.0, input, BUFFER_LEN) ; Chris@0: Chris@0: if (argc == 1) Chris@0: single_run () ; Chris@0: else if (argc == 3 && strcmp (argv [1], "--best-of") == 0) Chris@0: { int run_count = atoi (argv [2]) ; Chris@0: Chris@0: if (run_count < 1 || run_count > 20) Chris@0: { printf ("Please be sensible. Run count should be in range (1, 10].\n") ; Chris@0: exit (1) ; Chris@0: } ; Chris@0: Chris@0: multi_run (run_count) ; Chris@0: } Chris@0: else Chris@0: usage_exit (argv [0]) ; Chris@0: Chris@0: puts ( Chris@0: " Duration is in seconds.\n" Chris@0: " Throughput is in frames/sec (more is better).\n" Chris@0: ) ; Chris@0: Chris@0: return 0 ; Chris@0: } /* main */ Chris@0: