- count the number of bits correctly
- more check - tweak numbers - use more accurate time
This commit is contained in:
parent
ed36af787f
commit
6f39b50ccf
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: select.c,v 1.2 2008/03/21 16:03:33 ad Exp $ */
|
||||
/* $NetBSD: select.c,v 1.3 2011/11/02 16:49:12 yamt Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c)2008 YAMAMOTO Takashi,
|
||||
|
@ -29,10 +29,13 @@
|
|||
#define FD_SETSIZE 65536
|
||||
#include <sys/select.h>
|
||||
#include <sys/atomic.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -40,6 +43,7 @@
|
|||
|
||||
#define NPIPE 128
|
||||
#define NTHREAD 64
|
||||
#define NBALLS 5
|
||||
#define VERBOSE 0
|
||||
|
||||
#if !defined(RANDOM_MAX)
|
||||
|
@ -48,7 +52,7 @@
|
|||
|
||||
int fds[NPIPE][2];
|
||||
|
||||
unsigned count;
|
||||
volatile unsigned count;
|
||||
|
||||
pthread_barrier_t barrier;
|
||||
|
||||
|
@ -97,10 +101,11 @@ f(void *dummy)
|
|||
abort();
|
||||
}
|
||||
if (random() & 1) {
|
||||
assert(!FD_ISSET(fd, &set));
|
||||
FD_SET(fd, &set);
|
||||
nfd++;
|
||||
if (fd > maxfd) {
|
||||
maxfd = fd;
|
||||
nfd++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -127,6 +132,12 @@ f(void *dummy)
|
|||
(void *)pthread_self(), ret);
|
||||
abort();
|
||||
}
|
||||
if (ret > NBALLS) {
|
||||
fprintf(stderr, "[%p] unexpected return value %d"
|
||||
" > NBALLS\n",
|
||||
(void *)pthread_self(), ret);
|
||||
abort();
|
||||
}
|
||||
nfd = 0;
|
||||
for (fd = 0; fd <= maxfd; fd++) {
|
||||
if (FD_ISSET(fd, &set)) {
|
||||
|
@ -167,6 +178,10 @@ main(int argc, char *argv[])
|
|||
pthread_t pt[NTHREAD];
|
||||
int i;
|
||||
unsigned int secs;
|
||||
struct timeval start_tv;
|
||||
struct timeval end_tv;
|
||||
uint64_t usecs;
|
||||
unsigned int result;
|
||||
|
||||
secs = atoi(argv[1]);
|
||||
|
||||
|
@ -190,12 +205,17 @@ main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
pthread_barrier_wait(&barrier);
|
||||
gettimeofday(&start_tv, NULL);
|
||||
assert(count == 0);
|
||||
for (i = 0; i < NBALLS; i++) {
|
||||
dowrite();
|
||||
dowrite();
|
||||
dowrite();
|
||||
dowrite();
|
||||
|
||||
}
|
||||
sleep(secs);
|
||||
printf("%u / %u = %lf\n", count, secs, (double)count / secs);
|
||||
gettimeofday(&end_tv, NULL);
|
||||
result = count;
|
||||
usecs = (end_tv.tv_sec - start_tv.tv_sec) * 1000000
|
||||
+ end_tv.tv_usec - start_tv.tv_usec;
|
||||
printf("%u / %f = %f\n", result, (double)usecs / 1000000,
|
||||
(double)result / usecs * 1000000);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue