9 static struct timeval tp1,tp2;
10 static size_t block_size = 64 * 1024;
12 static void start_timer()
14 gettimeofday(&tp1,NULL);
17 static double end_timer()
19 gettimeofday(&tp2,NULL);
20 return((tp2.tv_sec - tp1.tv_sec) +
21 (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
25 static void write_file(char *fname)
28 static double total, thisrun;
32 buf = malloc(block_size);
35 printf("Malloc of %d failed\n", block_size);
39 fd = open(fname, O_WRONLY|O_SYNC);
46 while ((n = write(fd, buf, block_size)) > 0) {
49 if (end_timer() >= 1.0) {
50 printf("%d MB %g MB/sec\n",
52 (thisrun*1.0e-6)/end_timer());
63 static void usage(void)
66 writefiles - writes to a list of files, showing throughput
68 Usage: writefiles [options] <files>
71 -B size set the block size in bytes
73 WARNING: writefiles is a destructive test!
79 int main(int argc, char *argv[])
86 while ((c = getopt(argc, argv, "B:h")) != -1) {
89 block_size = strtol(optarg, NULL, 0);
110 for (i=0; i<argc; i++) {