X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=microbench%2Freadbench.c;h=043a2cf6df5ed402be8dfb4911b14836bcef8f9e;hb=99b1c3a692a5c6f0c3f6b3affcf34609555c5ebd;hp=88eb8884d00a75bb0eb3d990cc72c121b6b2325b;hpb=9882dff622103ee844eb1af5608ac48157ecfabb;p=bluesky.git diff --git a/microbench/readbench.c b/microbench/readbench.c index 88eb888..043a2cf 100644 --- a/microbench/readbench.c +++ b/microbench/readbench.c @@ -1,11 +1,13 @@ +#include +#include +#include +#include #include #include -#include -#include -#include -#include +#include +#include #include -#include +#include struct thread_state { pthread_t thread; @@ -55,12 +57,17 @@ void *benchmark_thread(void *arg) struct thread_state *ts = (struct thread_state *)arg; char namebuf[64]; - sprintf(namebuf, "file-%d", ts->thread_num); + sprintf(namebuf, "file-%d", ts->thread_num + 1); printf("Opening %s\n", namebuf); int64_t start, end; start = now_hires(); + + struct stat stat_buf; + stat(namebuf, &stat_buf); + +#if 0 FILE *f = fopen(namebuf, "rb"); if (f == NULL) { perror("fopen"); @@ -69,11 +76,12 @@ void *benchmark_thread(void *arg) char buf[4096]; fread(buf, 1, sizeof(buf), f); +#endif end = now_hires(); printf("Thread %d: Time = %"PRIi64"\n", ts->thread_num, end - start); - fclose(f); + // fclose(f); return NULL; } @@ -96,11 +104,20 @@ void wait_thread(int n) int main(int argc, char *argv[]) { - for (int i = 0; i < 8; i++) { + int threads = 8; + + if (argc > 1) + threads = atoi(argv[1]); + if (threads > MAX_THREADS) + threads = MAX_THREADS; + + printf("Testing with %d threads\n", threads); + + for (int i = 0; i < threads; i++) { launch_thread(i); } - for (int i = 0; i < 8; i++) { + for (int i = 0; i < threads; i++) { wait_thread(i); }