]>
iEval git - audio-libsamplerate.git/blob - throughput_test.c
10efe852f4e9f5641b67c9ad17e46300aa335ef3
2 ** Copyright (c) 2004-2016, Erik de Castro Lopo <erikd@mega-nerd.com>
3 ** All rights reserved.
5 ** This code is released under 2-clause BSD license. Please see the
6 ** file at : https://github.com/erikd/libsamplerate/blob/master/COPYING
15 #include <samplerate.h>
20 #include "float_cast.h"
22 #define BUFFER_LEN (1<<16)
24 static float input
[BUFFER_LEN
] ;
25 static float output
[BUFFER_LEN
] ;
28 throughput_test (int converter
, long best_throughput
)
30 clock_t start_time
, clock_time
;
32 long total_frames
= 0, throughput
;
35 printf (" %-30s ", src_get_name (converter
)) ;
38 src_data
.data_in
= input
;
39 src_data
.input_frames
= ARRAY_LEN (input
) ;
41 src_data
.data_out
= output
;
42 src_data
.output_frames
= ARRAY_LEN (output
) ;
44 src_data
.src_ratio
= 0.99 ;
48 start_time
= clock () ;
52 if ((error
= src_simple (&src_data
, converter
, 1)) != 0)
53 { puts (src_strerror (error
)) ;
57 total_frames
+= src_data
.output_frames_gen
;
59 clock_time
= clock () - start_time
;
60 duration
= (1.0 * clock_time
) / CLOCKS_PER_SEC
;
62 while (duration
< 3.0) ;
64 if (src_data
.input_frames_used
!= ARRAY_LEN (input
))
65 { printf ("\n\nLine %d : input frames used %ld should be %d\n", __LINE__
, src_data
.input_frames_used
, ARRAY_LEN (input
)) ;
69 if (fabs (src_data
.src_ratio
* src_data
.input_frames_used
- src_data
.output_frames_gen
) > 2)
70 { printf ("\n\nLine %d : input / output length mismatch.\n\n", __LINE__
) ;
71 printf (" input len : %d\n", ARRAY_LEN (input
)) ;
72 printf (" output len : %ld (should be %g +/- 2)\n\n", src_data
.output_frames_gen
,
73 floor (0.5 + src_data
.src_ratio
* src_data
.input_frames_used
)) ;
77 throughput
= lrint (floor (total_frames
/ duration
)) ;
79 if (best_throughput
== 0)
80 { best_throughput
= MAX (throughput
, best_throughput
) ;
81 printf ("%5.2f %10ld\n", duration
, throughput
) ;
84 { best_throughput
= MAX (throughput
, best_throughput
) ;
85 printf ("%5.2f %10ld %10ld\n", duration
, throughput
, best_throughput
) ;
89 return best_throughput
;
90 } /* throughput_test */
96 printf ("\n CPU name : %s\n", get_cpu_name ()) ;
100 " Converter Duration Throughput\n"
101 " -----------------------------------------------------------"
104 throughput_test (SRC_ZERO_ORDER_HOLD
, 0) ;
105 throughput_test (SRC_LINEAR
, 0) ;
106 throughput_test (SRC_SINC_FASTEST
, 0) ;
107 throughput_test (SRC_SINC_MEDIUM_QUALITY
, 0) ;
108 throughput_test (SRC_SINC_BEST_QUALITY
, 0) ;
115 multi_run (int run_count
)
116 { long zero_order_hold
= 0, linear
= 0 ;
117 long sinc_fastest
= 0, sinc_medium
= 0, sinc_best
= 0 ;
122 " Converter Duration Throughput Best Throughput\n"
123 " --------------------------------------------------------------------------------"
126 for (k
= 0 ; k
< run_count
; k
++)
127 { zero_order_hold
= throughput_test (SRC_ZERO_ORDER_HOLD
, zero_order_hold
) ;
128 linear
= throughput_test (SRC_LINEAR
, linear
) ;
129 sinc_fastest
= throughput_test (SRC_SINC_FASTEST
, sinc_fastest
) ;
130 sinc_medium
= throughput_test (SRC_SINC_MEDIUM_QUALITY
, sinc_medium
) ;
131 sinc_best
= throughput_test (SRC_SINC_BEST_QUALITY
, sinc_best
) ;
135 /* Let the CPU cool down. We might be running on a laptop. */
139 printf ("\n CPU name : %s\n", get_cpu_name ()) ;
143 " Converter Best Throughput\n"
144 " ------------------------------------------------"
146 printf (" %-30s %10ld\n", src_get_name (SRC_ZERO_ORDER_HOLD
), zero_order_hold
) ;
147 printf (" %-30s %10ld\n", src_get_name (SRC_LINEAR
), linear
) ;
148 printf (" %-30s %10ld\n", src_get_name (SRC_SINC_FASTEST
), sinc_fastest
) ;
149 printf (" %-30s %10ld\n", src_get_name (SRC_SINC_MEDIUM_QUALITY
), sinc_medium
) ;
150 printf (" %-30s %10ld\n", src_get_name (SRC_SINC_BEST_QUALITY
), sinc_best
) ;
156 usage_exit (const char * argv0
)
157 { const char * cptr
;
159 if ((cptr
= strrchr (argv0
, '/')) != NULL
)
164 " %s - Single run of the throughput test.\n"
165 " %s --best-of N - Do N runs of test a print bext result.\n"
173 main (int argc
, char ** argv
)
176 memset (input
, 0, sizeof (input
)) ;
178 gen_windowed_sines (1, &freq
, 1.0, input
, BUFFER_LEN
) ;
182 else if (argc
== 3 && strcmp (argv
[1], "--best-of") == 0)
183 { int run_count
= atoi (argv
[2]) ;
185 if (run_count
< 1 || run_count
> 20)
186 { printf ("Please be sensible. Run count should be in range (1, 10].\n") ;
190 multi_run (run_count
) ;
193 usage_exit (argv
[0]) ;
196 " Duration is in seconds.\n"
197 " Throughput is in samples/sec (more is better).\n"
This page took 0.060095 seconds and 3 git commands to generate.