-
-
Save dcolascione/ae9be560ecadc349c25e4f1e97648b99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <pthread.h> | |
#include <stdlib.h> | |
#include <sys/time.h> | |
#include <stdio.h> | |
static void* | |
thread_func(void* arg) | |
{ | |
return NULL; | |
} | |
double | |
tv2double(struct timeval tv) | |
{ | |
return (double) tv.tv_sec + (double) tv.tv_usec / 1e6; | |
} | |
int | |
main() | |
{ | |
pthread_t thread; | |
void* rv; | |
unsigned iters = 1e6; | |
struct timeval start; | |
gettimeofday(&start, NULL); | |
for (unsigned i = 0; i < iters; ++i) { | |
if (pthread_create(&thread, NULL, thread_func, NULL)) | |
abort(); | |
if (pthread_join(thread, &rv)) | |
abort(); | |
} | |
struct timeval end; | |
gettimeofday(&end, NULL); | |
double elapsed = tv2double(end) - tv2double(start); | |
printf("%u iterations in %g seconds: %g iters/second\n", | |
iters, elapsed, iters / elapsed); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment