- 论坛徽章:
- 0
|
- #include <stdio.h>
- #include <stddef.h>
- #include <unistd.h>
- #include <sys/select.h>
- /* According to earlier standards */
- #include <sys/time.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <errno.h>
- #include <time.h>
- #include <signal.h>
- #include <string.h>
-
- #define log printf
- static void sig_usr1()
- {
- }
- int main()
- {
- struct timeval timeout;
- unsigned int count = 0;
- struct timespec startTime, stopTime, diffTime ;
- int ret = 0;
- signal(SIGINT,sig_usr1);
- log("Starting.....\n");
- clock_gettime(CLOCK_MONOTONIC, &startTime);
- #define TIMEOUT 1000
- while(count < 1000)
- {
- timeout.tv_sec = 0;
- timeout.tv_usec = TIMEOUT * 1000;
- if (0 > (ret = select(1, NULL, NULL, NULL, &timeout)))
- {
- log("ret = %d(errno: %d): %s\n", ret, errno, strerror(errno));
- break;
- }
- ++count;
- }
- clock_gettime(CLOCK_MONOTONIC, &stopTime);
- printf("count:%d, time:\n%ld\n%d\n", count,
- (stopTime.tv_sec - startTime.tv_sec) *1000 +
- (stopTime.tv_nsec - startTime.tv_nsec)/1000000,
- count * TIMEOUT
- );
- return 0;
- }
复制代码 |
|