10 static struct timeval tp1,tp2;
11 static size_t block_size = 64 * 1024;
14 static void start_timer()
16 gettimeofday(&tp1,NULL);
19 static double end_timer()
21 gettimeofday(&tp2,NULL);
22 return((tp2.tv_sec - tp1.tv_sec) +
23 (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
27 static void write_file(char *fname)
30 static double total, thisrun;
34 buf = malloc(block_size);
37 printf("Malloc of %d failed\n", (int)block_size);
41 fd = open(fname, O_WRONLY|(osync?O_SYNC:0));
48 while ((n = write(fd, buf, block_size)) > 0) {
51 if (end_timer() >= 1.0) {
52 time_t t = time(NULL);
53 printf("%6d MB %.3f MB/sec %s",
55 (thisrun*1.0e-6)/end_timer(),
67 static void usage(void)
70 "writefiles - writes to a list of files, showing throughput\n" \
72 "Usage: writefiles [options] <files>\n" \
75 " -B size set the block size in bytes\n" \
78 "WARNING: writefiles is a destructive test!\n" \
84 int main(int argc, char *argv[])
91 while ((c = getopt(argc, argv, "B:hs")) != -1) {
94 block_size = strtol(optarg, NULL, 0);
118 for (i=0; i<argc; i++) {