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;
33 void *benchmark_thread(void *arg)
35 struct thread_state *ts = (struct thread_state *)arg;
38 sprintf(namebuf, "file-%d", ts->thread_num + 1);
39 printf("Opening %s\n", namebuf);
46 stat(namebuf, &stat_buf);
49 printf("Thread %d: Time = %"PRIi64"\n", ts->thread_num, end - start);
54 void launch_thread(int i)
56 threads[i].thread_num = i;
57 printf("Launching thread %d...\n", i);
58 if (pthread_create(&threads[i].thread, NULL, benchmark_thread, &threads[i]) != 0) {
59 fprintf(stderr, "Error launching thread!\n");
64 void wait_thread(int n)
67 pthread_join(threads[n].thread, &result);
70 int main(int argc, char *argv[])
75 threads = atoi(argv[1]);
76 if (threads > MAX_THREADS)
77 threads = MAX_THREADS;
79 printf("Testing with %d threads\n", threads);
81 for (int i = 0; i < threads; i++) {
85 for (int i = 0; i < threads; i++) {