]>
iEval git - audio-libsamplerate.git/blob - multichan_throughput_test.c
1c45b36baa687f85f61b830ec194e9bd8e24fe3b
2 ** Copyright (c) 2008-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<<17)
24 static float input
[BUFFER_LEN
] ;
25 static float output
[BUFFER_LEN
] ;
28 throughput_test (int converter
, int channels
, long best_throughput
)
30 clock_t start_time
, clock_time
;
32 long total_frames
= 0, throughput
;
35 printf (" %-30s %2d ", src_get_name (converter
), channels
) ;
38 src_data
.data_in
= input
;
39 src_data
.input_frames
= ARRAY_LEN (input
) / channels
;
41 src_data
.data_out
= output
;
42 src_data
.output_frames
= ARRAY_LEN (output
) / channels
;
44 src_data
.src_ratio
= 0.99 ;
48 start_time
= clock () ;
52 if ((error
= src_simple (&src_data
, converter
, channels
)) != 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
< 5.0) ;
64 if (src_data
.input_frames_used
!= src_data
.input_frames
)
65 { printf ("\n\nLine %d : input frames used %ld should be %ld\n", __LINE__
, src_data
.input_frames_used
, src_data
.input_frames
) ;
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
) / channels
) ;
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
) ;
88 return best_throughput
;
89 } /* throughput_test */
93 { const int max_channels
= 10 ;
96 printf ("\n CPU name : %s\n", get_cpu_name ()) ;
100 " Converter Channels Duration Throughput\n"
101 " ---------------------------------------------------------------------"
104 for (k
= 1 ; k
<= max_channels
/ 2 ; k
++)
105 throughput_test (SRC_SINC_FASTEST
, k
, 0) ;
108 for (k
= 1 ; k
<= max_channels
/ 2 ; k
++)
109 throughput_test (SRC_SINC_MEDIUM_QUALITY
, k
, 0) ;
112 for (k
= 1 ; k
<= max_channels
; k
++)
113 throughput_test (SRC_SINC_BEST_QUALITY
, k
, 0) ;
120 multi_run (int run_count
)
123 printf ("\n CPU name : %s\n", get_cpu_name ()) ;
127 " Converter Channels Duration Throughput Best Throughput\n"
128 " ----------------------------------------------------------------------------------------"
131 for (ch
= 1 ; ch
<= 5 ; ch
++)
132 { long sinc_fastest
= 0, sinc_medium
= 0, sinc_best
= 0 ;
134 for (k
= 0 ; k
< run_count
; k
++)
135 { sinc_fastest
= throughput_test (SRC_SINC_FASTEST
, ch
, sinc_fastest
) ;
136 sinc_medium
= throughput_test (SRC_SINC_MEDIUM_QUALITY
, ch
, sinc_medium
) ;
137 sinc_best
= throughput_test (SRC_SINC_BEST_QUALITY
, ch
, sinc_best
) ;
141 /* Let the CPU cool down. We might be running on a laptop. */
147 " Converter Best Throughput\n"
148 " ------------------------------------------------"
151 printf (" %-30s %10ld\n", src_get_name (SRC_SINC_FASTEST
), sinc_fastest
) ;
152 printf (" %-30s %10ld\n", src_get_name (SRC_SINC_MEDIUM_QUALITY
), sinc_medium
) ;
153 printf (" %-30s %10ld\n", src_get_name (SRC_SINC_BEST_QUALITY
), sinc_best
) ;
160 usage_exit (const char * argv0
)
161 { const char * cptr
;
163 if ((cptr
= strrchr (argv0
, '/')) != NULL
)
168 " %s - Single run of the throughput test.\n"
169 " %s --best-of N - Do N runs of test a print bext result.\n"
177 main (int argc
, char ** argv
)
180 memset (input
, 0, sizeof (input
)) ;
182 gen_windowed_sines (1, &freq
, 1.0, input
, BUFFER_LEN
) ;
186 else if (argc
== 3 && strcmp (argv
[1], "--best-of") == 0)
187 { int run_count
= atoi (argv
[2]) ;
189 if (run_count
< 1 || run_count
> 20)
190 { printf ("Please be sensible. Run count should be in range (1, 10].\n") ;
194 multi_run (run_count
) ;
197 usage_exit (argv
[0]) ;
200 " Duration is in seconds.\n"
201 " Throughput is in frames/sec (more is better).\n"
This page took 0.056873 seconds and 3 git commands to generate.