18 #define MAX_THREADS 128
19 struct thread_state threads[MAX_THREADS];
25 if (clock_gettime(CLOCK_REALTIME, &time) != 0) {
26 perror("clock_gettime");
30 return (int64_t)(time.tv_sec) * 1000000000 + time.tv_nsec;
36 FILE *f = fopen("writetest", "wb");
43 for (int i = 0; i < 16; i++) {
47 fwrite(buf, 1, sizeof(buf), f);
50 printf("Pass %d: Time = %"PRIi64"\n", i, end - start);
55 void *benchmark_thread(void *arg)
57 struct thread_state *ts = (struct thread_state *)arg;
60 sprintf(namebuf, "file-%d", ts->thread_num + 1);
61 printf("Opening %s\n", namebuf);
68 stat(namebuf, &stat_buf);
71 FILE *f = fopen(namebuf, "rb");
78 fread(buf, 1, sizeof(buf), f);
82 printf("Thread %d: Time = %"PRIi64"\n", ts->thread_num, end - start);
89 void launch_thread(int i)
91 threads[i].thread_num = i;
92 printf("Launching thread %d...\n", i);
93 if (pthread_create(&threads[i].thread, NULL, benchmark_thread, &threads[i]) != 0) {
94 fprintf(stderr, "Error launching thread!\n");
99 void wait_thread(int n)
102 pthread_join(threads[n].thread, &result);
105 int main(int argc, char *argv[])
110 threads = atoi(argv[1]);
111 if (threads > MAX_THREADS)
112 threads = MAX_THREADS;
114 printf("Testing with %d threads\n", threads);
116 for (int i = 0; i < threads; i++) {
120 for (int i = 0; i < threads; i++) {