2 test reading image frames from a directory
3 tridge@samba.org, March 2006
14 #define READ_SIZE 61440
16 static double total_time, min_time, max_time, total_bytes;
19 static struct timeval tp1,tp2;
21 static void start_timer()
23 gettimeofday(&tp1,NULL);
26 static double end_timer()
28 gettimeofday(&tp2,NULL);
29 return((tp2.tv_sec - tp1.tv_sec) +
30 (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
33 static void test_file(const char *fname)
36 unsigned char buf[READ_SIZE];
42 fd = open(fname, O_RDONLY);
44 printf("Failed to open %s\n", fname);
47 while ((n=read(fd, buf, READ_SIZE)) > 0) {
53 if (t > max_time) max_time = t;
54 if (min_time == 0 || t < min_time) min_time = t;
58 printf("%6.2fms %s\n", t*1000.0, fname);
61 static int name_cmp(char **n1, char **n2)
63 const char *s1=*n1, *s2=*n2;
64 /* try to do numerical sorting */
65 while (*s1 && *s1 == *s2) {
68 if (isdigit(*s1) || isdigit(*s2)) {
69 return atoi(s1) - atoi(s2);
71 return strcmp(s1, s2);
74 int main(int argc, char* argv[])
78 printf("readframes tester - tridge@samba.org\n");
81 printf("Usage: readframes <files>\n");
85 qsort(&argv[1], argc-1, sizeof(char *), name_cmp);
87 for (i=1;i<argc;i++) {
91 printf("\nProcessed %d files totalling %.2f MBytes\n",
92 num_files, total_bytes/(1024*1024));
93 printf("Speed was %.2f files/sec\n", num_files/total_time);
94 printf("Average speed was %.2fms per file\n", 1000.0*total_time/num_files);
95 printf("Worst: %.2fms Best: %.2fms\n", max_time*1000.0, min_time*1000.0);