comparison spandsp-0.0.3/user/speedtest.c @ 5:f762bf195c4b

import spandsp-0.0.3
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Fri, 25 Jun 2010 16:00:21 +0200
parents
children
comparison
equal deleted inserted replaced
4:26cd8f1ef0b1 5:f762bf195c4b
1 /*
2 speedtest.c
3 David Rowe
4 Created 27 Feb 2007
5
6 Measures execution speed of oslec in user mode.
7 */
8
9 /*
10 Copyright (C) 2007 David Rowe
11
12 All rights reserved.
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License version 2, as
16 published by the Free Software Foundation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 */
27
28 #include <assert.h>
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <sys/time.h>
32 #include <time.h>
33 #include <string.h>
34 #include <unistd.h>
35 #include <stdint.h>
36 #include <echo.h>
37
38 #define TAPS 128
39 #define N 8000 /* sample rate */
40 #define AMP 1000
41 #define SECS 10 /* number of simulated seconds to process */
42
43 /* constant for isr cycle averaging */
44
45 #define LTC 5
46
47 /* number of cycles we are using per call */
48
49 long long cycles_last = 0;
50 long long cycles_worst = 0;
51 long long cycles_average = 0;
52
53 #ifdef __BLACKFIN__
54 /* sample cycles register of Blackfin */
55
56 static inline unsigned int cycles(void) {
57 int ret;
58
59 __asm__ __volatile__
60 (
61 "%0 = CYCLES;\n\t"
62 : "=&d" (ret)
63 :
64 : "R1"
65 );
66
67 return ret;
68 }
69 #elif defined(__X86__) || defined (__i386) || defined (__x86_64__)
70 static __inline__ uint64_t cycles() {
71 uint64_t x;
72 __asm__ volatile ("rdtsc\n\t" : "=A" (x));
73 return x;
74 }
75 #else
76 static inline volatile unsigned int cycles(void) {
77 /* A dummy implementation for other architectures */
78 static unsigned int dummy_cycles = 1;
79 return dummy_cycles++;
80 }
81 #endif
82
83 int main(int argc, char **argv) {
84 int i,j;
85 echo_can_state_t *ec;
86 short tx[N],rx[N],clean;
87 struct timeval tv_before;
88 struct timeval tv_after;
89 unsigned long long t_before_ms, t_after_ms;
90 unsigned long long before_clocks, after_clocks;
91 unsigned long long t_ms;
92 unsigned long long start_cycles;
93 float mips_cpu, mips_per_ec;
94 FILE *f;
95
96 printf("\nTesting OSLEC with %d taps (%d ms tail)\n", TAPS, (TAPS*1000)/N);
97 for(i=0; i<N; i++) {
98 tx[i] = (short)AMP*(float)rand()/RAND_MAX;
99 rx[i] = tx[i]/4;
100 }
101
102 /* note NLP not switched on to make output more interesting for bit exact
103 testing */
104
105 ec = echo_can_create(TAPS, ECHO_CAN_USE_ADAPTION);
106
107 /* dump output of first run for bit exact testing when optimising */
108
109 f = fopen("out.txt","wt");
110 assert(f != NULL);
111 for(i=0; i<N; i++) {
112 clean = echo_can_update(ec, tx[i], rx[i]);
113 fprintf(f,"%d\n", clean);
114 }
115 fclose(f);
116
117 gettimeofday(&tv_before, NULL);
118 before_clocks = cycles();
119 for(j=0; j<SECS; j++) {
120
121 for(i=0; i<N; i++) {
122 start_cycles = cycles();
123 clean = echo_can_update(ec, tx[i], rx[i]);
124 cycles_last = cycles() - start_cycles;
125 cycles_average += (cycles_last - cycles_average +(1<<(LTC-1))) >> LTC;
126
127 if (cycles_last > cycles_worst)
128 cycles_worst = cycles_last;
129 }
130
131 }
132 after_clocks = cycles();
133 gettimeofday(&tv_after, NULL);
134 t_before_ms = 1000*tv_before.tv_sec + tv_before.tv_usec/1000;
135 t_after_ms = 1000*tv_after.tv_sec + tv_after.tv_usec/1000;
136 t_ms = t_after_ms - t_before_ms;
137
138 mips_cpu = (after_clocks - before_clocks)/(1E3*t_ms);
139 printf("CPU executes %5.2f MIPS\n-------------------------\n\n", mips_cpu);
140
141 printf("Method 1: gettimeofday() at start and end\n");
142 printf(" %llu ms for %ds of speech\n", t_ms, SECS);
143 mips_per_ec = mips_cpu/((float)SECS*1E3/(float)t_ms);
144 printf(" %5.2f MIPS\n", mips_per_ec);
145 printf(" %5.2f instances possible at 100%% CPU load\n",
146 (float)SECS*1E3/(float)t_ms);
147
148 printf("Method 2: samples clock cycles at start and end\n");
149 printf(" %5.2f MIPS\n", (after_clocks - before_clocks)/(1E6*SECS));
150 printf(" %5.2f instances possible at 100%% CPU load\n",
151 mips_cpu/((after_clocks - before_clocks)/(1E6*SECS)));
152
153 printf("Method 3: samples clock cycles for each call, IIR average\n");
154 mips_per_ec = 8*(float)cycles_average/1000;
155 printf(" cycles_worst %lld cycles_last %lld cycles_av: %lld"
156 "\n %5.2f MIPS\n",
157 cycles_worst, cycles_last, cycles_average, mips_per_ec);
158 printf(" %5.2f instances possible at 100%% CPU load\n", mips_cpu/mips_per_ec);
159
160 return 0;
161 }
162

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.