added writesize
authorAndrew Tridgell <tridge@samba.org>
Mon, 26 Nov 2007 05:53:11 +0000 (16:53 +1100)
committerAndrew Tridgell <tridge@samba.org>
Mon, 26 Nov 2007 05:53:11 +0000 (16:53 +1100)
win32/writefiles/writefiles.c
win32/writefiles/writefiles.exe

index 391dc5835819f8970b1cba13be9fe17169bb237a..f10858adc5886aa8d1d3fd8fe270aa434c1c3eb4 100755 (executable)
 #include "winbase.h"\r
 #include "writefiles.h"\r
 \r
-#define WRITE_SIZE 61440\r
-\r
 static double total_time, min_time, max_time, total_bytes;\r
 \r
 #define MIN(a,b) ((a)<(b)?(a):(b))\r
 \r
-static void test_file(const char *fname, unsigned long filesize)\r
+static void test_file(const char *fname, unsigned long filesize, unsigned writesize)\r
 {\r
        int fd;\r
-       unsigned char buf[WRITE_SIZE];\r
+       unsigned char *buf;\r
        LARGE_INTEGER counter1, counter2, freq;\r
        double t;\r
        int n;\r
        HANDLE h;\r
        DWORD nwritten;\r
 \r
+       buf = malloc(writesize);\r
+\r
        QueryPerformanceCounter(&counter1);\r
 \r
         h = CreateFile (\r
@@ -42,12 +42,13 @@ static void test_file(const char *fname, unsigned long filesize)
 \r
        if (h == INVALID_HANDLE_VALUE) {\r
                printf("Failed to open %s\n", fname);\r
+               free(buf);\r
                return;\r
        }\r
 \r
-       memset(buf, 0x42, WRITE_SIZE);\r
+       memset(buf, 0x42, writesize);\r
 \r
-       while (WriteFile(h, buf, MIN(WRITE_SIZE, filesize), &nwritten, NULL) && \r
+       while (WriteFile(h, buf, MIN(writesize, filesize), &nwritten, NULL) && \r
               nwritten != 0 &&\r
               filesize >= 0) {\r
                total_bytes += nwritten;\r
@@ -65,6 +66,7 @@ static void test_file(const char *fname, unsigned long filesize)
        total_time += t;\r
 \r
        printf("%6.2fms %s\n", t*1000.0, fname);\r
+       free(buf);\r
 }\r
 \r
 \r
@@ -74,24 +76,26 @@ int main(int argc, char* argv[])
        const char *dir;\r
        unsigned long filesize;\r
        unsigned numfiles;\r
+       unsigned writesize;\r
 \r
        printf("writefiles tester - tridge@samba.org\n");\r
 \r
-       if (argc < 4) {\r
-               printf("Usage: writefiles <directory> <filesize> <numfiles>\n");\r
+       if (argc < 5) {\r
+               printf("Usage: writefiles <directory> <filesize> <numfiles> <writesize>\n");\r
                exit(1);\r
        }\r
 \r
        dir = argv[1];\r
        filesize = strtoul(argv[2], NULL, 0);\r
        numfiles = strtoul(argv[3], NULL, 0);\r
+       writesize = strtoul(argv[4], NULL, 0);\r
 \r
        printf("writing %u files in %s\n", numfiles, dir);\r
 \r
        for (i=0;i<numfiles;i++) {\r
                char fname[1024];\r
                sprintf(fname, "%s\\file%u.dat", dir, i);\r
-               test_file(fname, filesize);\r
+               test_file(fname, filesize, writesize);\r
        }\r
 \r
        printf("\nProcessed %d files totalling %.2f MBytes at %.2f MByte/s\n", \r
index 77c56d6950c811092bd21a0d5130924811918896..4ce18e8fea0c094dd330f0003e0e0baaad5b022d 100644 (file)
Binary files a/win32/writefiles/writefiles.exe and b/win32/writefiles/writefiles.exe differ