--- /dev/null
+CC=E:\VC98\bin\cl -nologo\r
+INCLUDES=-I \r
+CFLAGS=$(INCLUDES) -Zi\r
+LIBS=\r
+\r
+all: readframes\r
+\r
+clean:\r
+ del *~ *.obj readframes\r
+\r
+readframes: readframes.obj\r
+ $(CC) -o readframes readframes.obj $(LIBS)\r
+\r
+readframes.obj: readframes.h readframes.c\r
--- /dev/null
+/* \r
+ test reading image frames from a directory\r
+ tridge@samba.org, March 2006\r
+*/\r
+\r
+#define _WIN32_WINNT 0x0400\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <ctype.h>\r
+#include <fcntl.h>\r
+#include "windows.h"\r
+#include "winbase.h"\r
+#include "readframes.h"\r
+\r
+#define READ_SIZE 61440\r
+\r
+static double total_time, min_time, max_time, total_bytes;\r
+\r
+static void test_file(const char *fname)\r
+{\r
+ int fd;\r
+ unsigned char buf[READ_SIZE];\r
+ LARGE_INTEGER counter1, counter2, freq;\r
+ double t;\r
+ int n;\r
+ HANDLE h;\r
+ DWORD nread;\r
+\r
+ QueryPerformanceCounter(&counter1);\r
+\r
+ h = CreateFile (\r
+ fname, GENERIC_READ, \r
+ FILE_SHARE_READ,\r
+ NULL, \r
+ OPEN_EXISTING, \r
+ 0,\r
+ NULL\r
+ );\r
+\r
+ if (h == INVALID_HANDLE_VALUE) {\r
+ printf("Failed to open %s\n", fname);\r
+ return;\r
+ }\r
+\r
+ while (ReadFile(h, buf, READ_SIZE, &nread, NULL) && nread != 0) {\r
+ total_bytes += nread;\r
+ }\r
+ CloseHandle(h);\r
+ QueryPerformanceCounter(&counter2);\r
+\r
+ QueryPerformanceFrequency(&freq);\r
+\r
+ t = (1.0*counter2.QuadPart - 1.0*counter1.QuadPart) / (1.0*freq.QuadPart);\r
+\r
+ if (t > max_time) max_time = t;\r
+ if (min_time == 0 || t < min_time) min_time = t;\r
+ total_time += t;\r
+\r
+ printf("%6.2fms %s\n", t*1000.0, fname);\r
+}\r
+\r
+\r
+static int num_files;\r
+static char **file_list;\r
+\r
+static void test_directory(const char *dname)\r
+{\r
+ WIN32_FIND_DATA list;\r
+ HANDLE h;\r
+ TCHAR dir[MAX_PATH+1];\r
+\r
+ sprintf(dir, "%s\\*", dname);\r
+\r
+ h = FindFirstFile(dir, &list);\r
+ if (h == INVALID_HANDLE_VALUE) {\r
+ printf("No files in %s\n", dname);\r
+ return;\r
+ }\r
+ do {\r
+ TCHAR fname[MAX_PATH+1];\r
+ sprintf(fname, "%s\\%s", dname, list.cFileName);\r
+ if (strcmp(list.cFileName, ".") == 0 ||\r
+ strcmp(list.cFileName, "..") == 0) continue;\r
+ \r
+ if (list.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {\r
+ test_directory(fname);\r
+ } else {\r
+ if (file_list == NULL) {\r
+ file_list = malloc(sizeof(char *));\r
+ } else {\r
+ file_list = realloc(file_list, sizeof(char *)*(num_files+1));\r
+ }\r
+ file_list[num_files] = strdup(fname);\r
+ num_files++;\r
+ }\r
+ } while (FindNextFile(h, &list));\r
+ FindClose(h);\r
+}\r
+\r
+static int name_cmp(char **n1, char **n2)\r
+{\r
+ const char *s1=*n1, *s2=*n2;\r
+ /* try to do numerical sorting */\r
+ while (*s1 && *s1 == *s2) {\r
+ s1++; s2++;\r
+ }\r
+ if (isdigit(*s1) || isdigit(*s2)) {\r
+ return atoi(s1) - atoi(s2);\r
+ }\r
+ return strcmp(s1, s2);\r
+}\r
+\r
+int main(int argc, char* argv[])\r
+{\r
+ int i; \r
+\r
+ printf("readframes tester - tridge@samba.org\n");\r
+\r
+ if (argc < 2) {\r
+ printf("Usage: readframes <directory>\n");\r
+ exit(1);\r
+ }\r
+\r
+ for (i=1;i<argc;i++) {\r
+ printf("Testing on directory %s\n", argv[i]);\r
+ test_directory(argv[i]);\r
+ }\r
+\r
+ qsort(file_list, num_files, sizeof(char *), name_cmp);\r
+ \r
+ for (i=0;i<num_files;i++) {\r
+ test_file(file_list[i]);\r
+ }\r
+\r
+ printf("\nProcessed %d files totalling %.2f MBytes\n", \r
+ num_files, total_bytes/(1024*1024));\r
+ printf("Speed was %.2f files/sec\n", num_files/total_time);\r
+ printf("Average speed was %.2fms per file\n", 1000.0*total_time/num_files);\r
+ printf("Worst: %.2fms Best: %.2fms\n", max_time*1000.0, min_time*1000.0);\r
+\r
+ return 0;\r
+}\r
--- /dev/null
+/*
+ test reading image frames from a directory
+ tridge@samba.org, March 2006
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/time.h>
+#include <time.h>
+
+
+#define READ_SIZE 61440
+
+static double total_time, min_time, max_time, total_bytes;
+static int num_files;
+
+static struct timeval tp1,tp2;
+
+static void start_timer()
+{
+ gettimeofday(&tp1,NULL);
+}
+
+static double end_timer()
+{
+ gettimeofday(&tp2,NULL);
+ return((tp2.tv_sec - tp1.tv_sec) +
+ (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
+}
+
+static void test_file(const char *fname)
+{
+ int fd;
+ unsigned char buf[READ_SIZE];
+
+ double t;
+ int n;
+
+ start_timer();
+ fd = open(fname, O_RDONLY);
+ if (fd == -1) {
+ printf("Failed to open %s\n", fname);
+ return;
+ }
+ while ((n=read(fd, buf, READ_SIZE)) > 0) {
+ total_bytes += n;
+ }
+ close(fd);
+ t = end_timer();
+
+ if (t > max_time) max_time = t;
+ if (min_time == 0 || t < min_time) min_time = t;
+ total_time += t;
+ num_files++;
+
+ printf("%6.2fms %s\n", t*1000.0, fname);
+}
+
+static int name_cmp(char **n1, char **n2)
+{
+ const char *s1=*n1, *s2=*n2;
+ /* try to do numerical sorting */
+ while (*s1 && *s1 == *s2) {
+ s1++; s2++;
+ }
+ if (isdigit(*s1) || isdigit(*s2)) {
+ return atoi(s1) - atoi(s2);
+ }
+ return strcmp(s1, s2);
+}
+
+int main(int argc, char* argv[])
+{
+ int i;
+
+ printf("readframes tester - tridge@samba.org\n");
+
+ if (argc < 2) {
+ printf("Usage: readframes <files>\n");
+ exit(1);
+ }
+
+ qsort(&argv[1], argc-1, sizeof(char *), name_cmp);
+
+ for (i=1;i<argc;i++) {
+ test_file(argv[i]);
+ }
+
+ printf("\nProcessed %d files totalling %.2f MBytes\n",
+ num_files, total_bytes/(1024*1024));
+ printf("Speed was %.2f files/sec\n", num_files/total_time);
+ printf("Average speed was %.2fms per file\n", 1000.0*total_time/num_files);
+ printf("Worst: %.2fms Best: %.2fms\n", max_time*1000.0, min_time*1000.0);
+
+ return 0;
+}
--- /dev/null
+CC=E:\VC98\bin\cl -nologo\r
+INCLUDES=-I \r
+CFLAGS=$(INCLUDES) -Zi\r
+LIBS=\r
+\r
+all: writefiles\r
+\r
+clean:\r
+ del *~ *.obj writefiles\r
+\r
+writefiles: writefiles.obj\r
+ $(CC) -o writefiles writefiles.obj $(LIBS)\r
+\r
+writefiles.obj: writefiles.h writefiles.c\r
--- /dev/null
+/* \r
+ test reading image frames from a directory\r
+ tridge@samba.org, March 2006\r
+*/\r
+\r
+#define _WIN32_WINNT 0x0400\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <ctype.h>\r
+#include <fcntl.h>\r
+#include "windows.h"\r
+#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
+{\r
+ int fd;\r
+ unsigned char buf[WRITE_SIZE];\r
+ LARGE_INTEGER counter1, counter2, freq;\r
+ double t;\r
+ int n;\r
+ HANDLE h;\r
+ DWORD nwritten;\r
+\r
+ QueryPerformanceCounter(&counter1);\r
+\r
+ h = CreateFile (\r
+ fname, GENERIC_WRITE, \r
+ FILE_SHARE_READ|FILE_SHARE_WRITE,\r
+ NULL, \r
+ CREATE_ALWAYS, \r
+ 0,\r
+ NULL\r
+ );\r
+\r
+ if (h == INVALID_HANDLE_VALUE) {\r
+ printf("Failed to open %s\n", fname);\r
+ return;\r
+ }\r
+\r
+ memset(buf, 0x42, WRITE_SIZE);\r
+\r
+ while (WriteFile(h, buf, MIN(WRITE_SIZE, filesize), &nwritten, NULL) && \r
+ nwritten != 0 &&\r
+ filesize >= 0) {\r
+ total_bytes += nwritten;\r
+ filesize -= nwritten;\r
+ }\r
+ CloseHandle(h);\r
+ QueryPerformanceCounter(&counter2);\r
+\r
+ QueryPerformanceFrequency(&freq);\r
+\r
+ t = (1.0*counter2.QuadPart - 1.0*counter1.QuadPart) / (1.0*freq.QuadPart);\r
+\r
+ if (t > max_time) max_time = t;\r
+ if (min_time == 0 || t < min_time) min_time = t;\r
+ total_time += t;\r
+\r
+ printf("%6.2fms %s\n", t*1000.0, fname);\r
+}\r
+\r
+\r
+int main(int argc, char* argv[])\r
+{\r
+ unsigned i; \r
+ const char *dir;\r
+ unsigned long filesize;\r
+ unsigned numfiles;\r
+\r
+ printf("writefiles tester - tridge@samba.org\n");\r
+\r
+ if (argc < 4) {\r
+ printf("Usage: writefiles <directory> <filesize> <numfiles>\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
+\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
+ }\r
+\r
+ printf("\nProcessed %d files totalling %.2f MBytes at %.2f MByte/s\n", \r
+ numfiles, total_bytes/(1024*1024), total_bytes/(total_time*1024*1024));\r
+ printf("Speed was %.2f files/sec\n", numfiles/total_time);\r
+ printf("Average speed was %.2fms per file\n", 1000.0*total_time/numfiles);\r
+ printf("Worst: %.2fms Best: %.2fms\n", max_time*1000.0, min_time*1000.0);\r
+\r
+ return 0;\r
+}\r