19 #define MAX_THREADS 128
20 struct thread_state threads[MAX_THREADS];
26 if (clock_gettime(CLOCK_REALTIME, &time) != 0) {
27 perror("clock_gettime");
31 return (int64_t)(time.tv_sec) * 1000000000 + time.tv_nsec;
37 FILE *f = fopen("writetest", "wb");
44 for (int i = 0; i < 16; i++) {
48 fwrite(buf, 1, sizeof(buf), f);
51 printf("Pass %d: Time = %"PRIi64"\n", i, end - start);
56 void *benchmark_thread(void *arg)
58 struct thread_state *ts = (struct thread_state *)arg;
60 printf("Opening %s\n", ts->filename);
66 //struct stat stat_buf;
67 //stat(namebuf, &stat_buf);
69 FILE *f = fopen(ts->filename, "rb");
76 while (fread(buf, 1, sizeof(buf), f) > 0) { }
79 printf("Thread %d: Time = %"PRIi64"\n", ts->thread_num, end - start);
86 void launch_thread(int i, const char *filename)
88 threads[i].thread_num = i;
89 threads[i].filename = filename;
90 printf("Launching thread %d [%s]...\n", i, filename);
91 if (pthread_create(&threads[i].thread, NULL, benchmark_thread, &threads[i]) != 0) {
92 fprintf(stderr, "Error launching thread!\n");
97 void wait_thread(int n)
100 pthread_join(threads[n].thread, &result);
103 int main(int argc, char *argv[])
105 int threads = argc - 1;
107 printf("Testing with %d threads\n", threads);
109 for (int i = 0; i < threads; i++) {
110 launch_thread(i, argv[i + 1]);
113 for (int i = 0; i < threads; i++) {