@@ -94,7 +94,7 @@ static double rand_double( void ) {
94
94
* @param len array length
95
95
* @return elapsed time in seconds
96
96
*/
97
- static double benchmark ( int iterations , int len ) {
97
+ static double benchmark1 ( int iterations , int len ) {
98
98
double elapsed ;
99
99
double x [ len ];
100
100
double y [ len ];
@@ -120,6 +120,39 @@ static double benchmark( int iterations, int len ) {
120
120
return elapsed ;
121
121
}
122
122
123
+ /**
124
+ * Runs a benchmark.
125
+ *
126
+ * @param iterations number of iterations
127
+ * @param len array length
128
+ * @return elapsed time in seconds
129
+ */
130
+ static double benchmark2 ( int iterations , int len ) {
131
+ double elapsed ;
132
+ double x [ len ];
133
+ double y [ len ];
134
+ double t ;
135
+ int i ;
136
+
137
+ for ( i = 0 ; i < len ; i ++ ) {
138
+ x [ i ] = ( rand_double ()* 20000.0 ) - 10000.0 ;
139
+ y [ i ] = 0.0 ;
140
+ }
141
+ t = tic ();
142
+ for ( i = 0 ; i < iterations ; i ++ ) {
143
+ c_dcopy_ndarray ( len , x , 1 , 0 , y , 1 , 0 );
144
+ if ( y [ 0 ] != y [ 0 ] ) {
145
+ printf ( "should not return NaN\n" );
146
+ break ;
147
+ }
148
+ }
149
+ elapsed = tic () - t ;
150
+ if ( y [ 0 ] != y [ 0 ] ) {
151
+ printf ( "should not return NaN\n" );
152
+ }
153
+ return elapsed ;
154
+ }
155
+
123
156
/**
124
157
* Main execution sequence.
125
158
*/
@@ -142,7 +175,14 @@ int main( void ) {
142
175
for ( j = 0 ; j < REPEATS ; j ++ ) {
143
176
count += 1 ;
144
177
printf ( "# c::%s:len=%d\n" , NAME , len );
145
- elapsed = benchmark ( iter , len );
178
+ elapsed = benchmark1 ( iter , len );
179
+ print_results ( iter , elapsed );
180
+ printf ( "ok %d benchmark finished\n" , count );
181
+ }
182
+ for ( j = 0 ; j < REPEATS ; j ++ ) {
183
+ count += 1 ;
184
+ printf ( "# c::%s:ndarray:len=%d\n" , NAME , len );
185
+ elapsed = benchmark2 ( iter , len );
146
186
print_results ( iter , elapsed );
147
187
printf ( "ok %d benchmark finished\n" , count );
148
188
}
0 commit comments