Skip to content

Commit 6e0f6c5

Browse files
authored
Merge pull request #2824 from martin-frbg/asumbench
Use POSIX2001 clock.gettime in asum benchmark if available
2 parents ed0f2d3 + 6f8fad8 commit 6e0f6c5

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

benchmark/asum.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,13 @@ int main(int argc, char *argv[]){
128128
int to = 200;
129129
int step = 1;
130130

131+
#if defined(__WIN32__) || defined(__WIN64__) || !defined(_POSIX_TIMERS)
131132
struct timeval start, stop;
132133
double time1,timeg;
134+
#else
135+
struct timespec start = { 0, 0 }, stop = { 0, 0 };
136+
double time1, timeg;
137+
#endif
133138

134139
argc--;argv++;
135140

@@ -160,26 +165,30 @@ int main(int argc, char *argv[]){
160165

161166
fprintf(stderr, " %6d : ", (int)m);
162167

163-
164168
for (l=0; l<loops; l++)
165169
{
166170

167171
for(i = 0; i < m * COMPSIZE * abs(inc_x); i++){
168172
x[i] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
169173
}
170-
174+
#if defined(__WIN32__) || defined(__WIN64__) || !defined(_POSIX_TIMERS)
171175
gettimeofday( &start, (struct timezone *)0);
172-
176+
#else
177+
clock_gettime(CLOCK_REALTIME, &start);
178+
#endif
173179
result = ASUM (&m, x, &inc_x);
174-
175-
gettimeofday( &stop, (struct timezone *)0);
176-
177-
time1 = (double)(stop.tv_sec - start.tv_sec) + (double)((stop.tv_usec - start.tv_usec)) * 1.e-6;
180+
#if defined(__WIN32__) || defined(__WIN64__) || !defined(_POSIX_TIMERS)
181+
clock_gettime(CLOCK_REALTIME, &stop);
182+
time1 = (double)(stop.tv_sec - start.tv_sec) + (double)((stop.tv_usec - start.tv_usec)) * 1.e-6;
183+
#else
184+
gettimeofday( &stop, (struct timezone *)0);
185+
time1 = (double)(stop.tv_sec - start.tv_sec) + (double)((stop.tv_nsec - start.tv_nsec)) / 1.e9;
186+
#endif
178187

179188
timeg += time1;
180189

181190
}
182-
191+
if (loops >1)
183192
timeg /= loops;
184193

185194
#ifdef COMPLEX

0 commit comments

Comments
 (0)