16 #define MAX_THREADS 128
17 struct thread_state threads[MAX_THREADS];
23 if (clock_gettime(CLOCK_REALTIME, &time) != 0) {
24 perror("clock_gettime");
28 return (int64_t)(time.tv_sec) * 1000000000 + time.tv_nsec;
34 FILE *f = fopen("writetest", "wb");
41 for (int i = 0; i < 16; i++) {
45 fwrite(buf, 1, sizeof(buf), f);
48 printf("Pass %d: Time = %"PRIi64"\n", i, end - start);
53 void *benchmark_thread(void *arg)
55 struct thread_state *ts = (struct thread_state *)arg;
58 sprintf(namebuf, "file-%d", ts->thread_num);
59 printf("Opening %s\n", namebuf);
64 FILE *f = fopen(namebuf, "rb");
71 fread(buf, 1, sizeof(buf), f);
74 printf("Thread %d: Time = %"PRIi64"\n", ts->thread_num, end - start);
81 void launch_thread(int i)
83 threads[i].thread_num = i;
84 printf("Launching thread %d...\n", i);
85 if (pthread_create(&threads[i].thread, NULL, benchmark_thread, &threads[i]) != 0) {
86 fprintf(stderr, "Error launching thread!\n");
91 void wait_thread(int n)
94 pthread_join(threads[n].thread, &result);
97 int main(int argc, char *argv[])
99 for (int i = 0; i < 8; i++) {
103 for (int i = 0; i < 8; i++) {