X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=microbench%2Freadbench.c;h=5a397e3102e771d1fc4ea1119e7f0ac5e1582c59;hb=67fc8c80ac31b2b89a17d6c258d9cbae6382142e;hp=043a2cf6df5ed402be8dfb4911b14836bcef8f9e;hpb=86765e018c4f08150e62b0a3272b0ab505da0983;p=bluesky.git diff --git a/microbench/readbench.c b/microbench/readbench.c index 043a2cf..5a397e3 100644 --- a/microbench/readbench.c +++ b/microbench/readbench.c @@ -11,6 +11,7 @@ struct thread_state { pthread_t thread; + const char *filename; int thread_num; long long timestamp; }; @@ -56,40 +57,37 @@ void *benchmark_thread(void *arg) { struct thread_state *ts = (struct thread_state *)arg; - char namebuf[64]; - sprintf(namebuf, "file-%d", ts->thread_num + 1); - printf("Opening %s\n", namebuf); + printf("Opening %s\n", ts->filename); int64_t start, end; start = now_hires(); - struct stat stat_buf; - stat(namebuf, &stat_buf); + //struct stat stat_buf; + //stat(namebuf, &stat_buf); -#if 0 - FILE *f = fopen(namebuf, "rb"); + FILE *f = fopen(ts->filename, "rb"); if (f == NULL) { perror("fopen"); return NULL; } - char buf[4096]; - fread(buf, 1, sizeof(buf), f); -#endif + char buf[65536]; + while (fread(buf, 1, sizeof(buf), f) > 0) { } end = now_hires(); printf("Thread %d: Time = %"PRIi64"\n", ts->thread_num, end - start); - // fclose(f); + fclose(f); return NULL; } -void launch_thread(int i) +void launch_thread(int i, const char *filename) { threads[i].thread_num = i; - printf("Launching thread %d...\n", i); + threads[i].filename = filename; + printf("Launching thread %d [%s]...\n", i, filename); if (pthread_create(&threads[i].thread, NULL, benchmark_thread, &threads[i]) != 0) { fprintf(stderr, "Error launching thread!\n"); exit(1); @@ -104,17 +102,12 @@ void wait_thread(int n) int main(int argc, char *argv[]) { - int threads = 8; - - if (argc > 1) - threads = atoi(argv[1]); - if (threads > MAX_THREADS) - threads = MAX_THREADS; + int threads = argc - 1; printf("Testing with %d threads\n", threads); for (int i = 0; i < threads; i++) { - launch_thread(i); + launch_thread(i, argv[i + 1]); } for (int i = 0; i < threads; i++) {