ref: d86441db3eb3b57d19124edda6018d330f2458ba
parent: 215bd037edbcdbd6e10c39e496ee95ee849ca972
author: Erik de Castro Lopo <erikd@mega-nerd.com>
date: Fri Sep 26 10:10:25 EDT 2008
tests/throughput_test.c : Add ability to do best-of N runs, print CPU type.
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,9 @@
* tests/util.[ch]
Add function print_cpu_name.
+ * tests/throughput_test.c
+ Add ability to do best-of N runs, print CPU type.
+
2008-09-17 Erik de Castro Lopo <erikd AT mega-nerd DOT com>
* configure.ac
--- a/tests/throughput_test.c
+++ b/tests/throughput_test.c
@@ -34,12 +34,12 @@
static float input [BUFFER_LEN] ;
static float output [BUFFER_LEN] ;
-static void
-throughput_test (int converter)
+static long
+throughput_test (int converter, long best_throughput)
{ SRC_DATA src_data ;
clock_t start_time, clock_time ;
double duration ;
- long total_frames = 0 ;
+ long total_frames = 0, throughput ;
int error ;
printf (" %-30s ", src_get_name (converter)) ;
@@ -53,7 +53,7 @@
src_data.src_ratio = 0.99 ;
- sleep (1) ;
+ sleep (2) ;
start_time = clock () ;
@@ -84,19 +84,28 @@
exit (1) ;
} ;
- printf ("%5.2f %10ld\n", duration, lrint (floor (total_frames / duration))) ;
+ throughput = lrint (floor (total_frames / duration)) ;
+ if (best_throughput == 0)
+ { best_throughput = MAX (throughput, best_throughput) ;
+ printf ("%5.2f %10ld\n", duration, throughput) ;
+ }
+ else
+ { best_throughput = MAX (throughput, best_throughput) ;
+ printf ("%5.2f %10ld %10ld\n", duration, throughput, best_throughput) ;
+ }
+
+
+ return best_throughput ;
} /* throughput_test */
+static void
+single_run (void)
+{
-int
-main (void)
-{ double freq ;
+ printf ("\n CPU : ") ;
+ print_cpu_name () ;
- memset (input, 0, sizeof (input)) ;
- freq = 0.01 ;
- gen_windowed_sines (1, &freq, 1.0, input, BUFFER_LEN) ;
-
puts (
"\n"
" Converter Duration Throughput\n"
@@ -103,16 +112,101 @@
" -----------------------------------------------------------"
) ;
- throughput_test (SRC_ZERO_ORDER_HOLD) ;
- throughput_test (SRC_LINEAR) ;
- throughput_test (SRC_SINC_FASTEST) ;
- throughput_test (SRC_SINC_MEDIUM_QUALITY) ;
- throughput_test (SRC_SINC_BEST_QUALITY) ;
+ throughput_test (SRC_ZERO_ORDER_HOLD, 0) ;
+ throughput_test (SRC_LINEAR, 0) ;
+ throughput_test (SRC_SINC_FASTEST, 0) ;
+ throughput_test (SRC_SINC_MEDIUM_QUALITY, 0) ;
+ throughput_test (SRC_SINC_BEST_QUALITY, 0) ;
+ puts ("") ;
+ return ;
+} /* single_run */
+
+static void
+multi_run (int run_count)
+{ long zero_order_hold = 0, linear = 0 ;
+ long sinc_fastest = 0, sinc_medium = 0, sinc_best = 0 ;
+ int k ;
+
puts (
"\n"
+ " Converter Duration Throughput Best Throughput\n"
+ " --------------------------------------------------------------------------------"
+ ) ;
+
+ for (k = 0 ; k < run_count ; k++)
+ { zero_order_hold = throughput_test (SRC_ZERO_ORDER_HOLD, zero_order_hold) ;
+ linear = throughput_test (SRC_LINEAR, linear) ;
+ sinc_fastest = throughput_test (SRC_SINC_FASTEST, sinc_fastest) ;
+ sinc_medium = throughput_test (SRC_SINC_MEDIUM_QUALITY, sinc_medium) ;
+ sinc_best = throughput_test (SRC_SINC_BEST_QUALITY, sinc_best) ;
+
+ puts ("") ;
+
+ /* Let the CPU cool down. We might be running on a laptop. */
+ sleep (10) ;
+ } ;
+
+ printf ("\n CPU name : ") ;
+ print_cpu_name () ;
+
+ puts (
+ "\n"
+ " Converter Best Throughput\n"
+ " ------------------------------------------------"
+ ) ;
+ printf (" %-30s %10ld\n", src_get_name (SRC_ZERO_ORDER_HOLD), zero_order_hold) ;
+ printf (" %-30s %10ld\n", src_get_name (SRC_LINEAR), linear) ;
+ printf (" %-30s %10ld\n", src_get_name (SRC_SINC_FASTEST), sinc_fastest) ;
+ printf (" %-30s %10ld\n", src_get_name (SRC_SINC_MEDIUM_QUALITY), sinc_medium) ;
+ printf (" %-30s %10ld\n", src_get_name (SRC_SINC_BEST_QUALITY), sinc_best) ;
+
+ puts ("") ;
+} /* multi_run */
+
+static void
+usage_exit (const char * argv0)
+{ const char * cptr ;
+
+ if ((cptr = strrchr (argv0, '/')) != NULL)
+ argv0 = cptr ;
+
+ printf (
+ "Usage :\n"
+ " %s - Single run of the throughput test.\n"
+ " %s --best-of N - Do N runs of test a print bext result.\n"
+ "\n",
+ argv0, argv0) ;
+
+ exit (0) ;
+} /* usage_exit */
+
+int
+main (int argc, char ** argv)
+{ double freq ;
+
+ memset (input, 0, sizeof (input)) ;
+ freq = 0.01 ;
+ gen_windowed_sines (1, &freq, 1.0, input, BUFFER_LEN) ;
+
+ if (argc == 1)
+ single_run () ;
+ else if (argc == 3 && strcmp (argv [1], "--best-of") == 0)
+ { int run_count = atoi (argv [2]) ;
+
+ if (run_count < 1 || run_count > 20)
+ { printf ("Please be sensible. Run count should be in range (1, 10].\n") ;
+ exit (1) ;
+ } ;
+
+ multi_run (run_count) ;
+ }
+ else
+ usage_exit (argv [0]) ;
+
+ puts (
" Duration is in seconds.\n"
- " Throughput is in samples/sec.\n"
+ " Throughput is in samples/sec (more is better).\n"
) ;
return 0 ;