shithub: libsamplerate

Download patch

ref: 19403f9148d1335bfc0ae8536dd22a518c3f6418
parent: 02f661e33bdbf388a772977a7a7bcbe87d881cf6
author: Erik de Castro Lopo <erikd@mega-nerd.com>
date: Fri Mar 7 17:58:10 EST 2008

tests/throughput_test.c : Radical improvements.

--- a/tests/throughput_test.c
+++ b/tests/throughput_test.c
@@ -27,21 +27,20 @@
 #include "util.h"
 
 #define BUFFER_LEN	(1<<16)
-#define SNR_LEN		(1<<16)
 
 static float input [BUFFER_LEN] ;
 static float output [BUFFER_LEN] ;
 
-int
-main (void)
+static void
+throughput_test (int converter)
 {	SRC_DATA src_data ;
 	clock_t start_time, clock_time ;
-	double freq ;
+	double duration ;
+	long total_frames = 0 ;
 	int error ;
 
-	memset (input, 0, sizeof (input)) ;
-	freq = 0.01 ;
-	gen_windowed_sines (1, &freq, 1.0, input, SNR_LEN) ;
+	printf ("    %-30s    ", src_get_name (converter)) ;
+	fflush (stdout) ;
 
 	src_data.data_in = input ;
 	src_data.input_frames = ARRAY_LEN (input) ;
@@ -53,13 +52,20 @@
 
 	start_time = clock () ;
 
-	if ((error = src_simple (&src_data, SRC_OLD_SINC_BEST_QUALITY, 1)) != 0)
-	{	puts (src_strerror (error)) ;
-		exit (1) ;
-		} ;
+	do
+	{
+		if ((error = src_simple (&src_data, converter, 1)) != 0)
+		{	puts (src_strerror (error)) ;
+			exit (1) ;
+			} ;
 
-	clock_time = clock () - start_time ;
+		total_frames += src_data.output_frames_gen ;
 
+		clock_time = clock () - start_time ;
+		duration = (1.0 * clock_time) / CLOCKS_PER_SEC ;
+	}
+	while (duration < 5.0) ;
+
 	if (src_data.input_frames_used != ARRAY_LEN (input))
 	{	printf ("\n\nLine %d : input frames used %ld should be %d\n", __LINE__, src_data.input_frames_used, ARRAY_LEN (input)) ;
 		exit (1) ;
@@ -73,9 +79,39 @@
 		exit (1) ;
 		} ;
 
-	printf ("Time       : %5.2f secs.\n", (1.0 * clock_time) / CLOCKS_PER_SEC) ;
-	printf ("Throughput : %d samples/sec\n", (int) floor (src_data.output_frames_gen / ((1.0 * clock_time) / CLOCKS_PER_SEC))) ;
-	printf ("SNR        : %6.2f dB\n", calculate_snr (output, SNR_LEN, 1)) ;
+	printf ("%5.2f          %10ld\n", duration, lrint (floor (total_frames / duration))) ;
+
+} /* throughput_test */
+
+
+int
+main (void)
+{	double freq ;
+
+	memset (input, 0, sizeof (input)) ;
+	freq = 0.01 ;
+	gen_windowed_sines (1, &freq, 1.0, input, BUFFER_LEN) ;
+
+	puts (
+		"\n"
+		"    Converter                        Duration        Throughput\n"
+		"    -----------------------------------------------------------"
+		) ;
+
+	throughput_test (SRC_ZERO_ORDER_HOLD) ;
+	throughput_test (SRC_LINEAR) ;
+	throughput_test (SRC_SINC_FASTEST) ;
+
+	throughput_test (SRC_OLD_SINC_MEDIUM_QUALITY) ;
+	throughput_test (SRC_SINC_MEDIUM_QUALITY) ;
+	throughput_test (SRC_OLD_SINC_BEST_QUALITY) ;
+	throughput_test (SRC_SINC_BEST_QUALITY) ;
+
+	puts (
+		"\n"
+		"            Duration is in seconds.\n"
+		"            Throughput is in samples/sec.\n"
+		) ;
 
 	return 0 ;
 } /* main */