summaryrefslogtreecommitdiff
path: root/legacy/eet/src/bin/eet_bench_main.c
blob: 88aa364b930ca79d8a7abbe6b8e272d245a6f581 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "Eet.h"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <limits.h>
#include <fnmatch.h>
#include <sys/time.h>
#include <time.h>

double
get_time(void)
{
   struct timeval      timev;
   
   gettimeofday(&timev, NULL);
   return (double)timev.tv_sec + (((double)timev.tv_usec) / 1000000);
}

int
main(int argc, char **argv)
{
   char *file;
   Eet_File *ef;
   char **items;
   int items_num;
   int i;
   double t1, t2;
   
   file = argv[1];
   ef = eet_open(file, EET_FILE_MODE_READ);
   if (ef)
     {
	items = eet_list(ef, "images/*", &items_num);
	for (i = 0; i < items_num; i++)
	  items[i] = strdup(items[i]);
	eet_close(ef);
     }
   else
     {
	printf("EEK. cannot load %s\n", file);
	exit(-1);
     }
   
   t1 = get_time();
   ef = eet_open(file, EET_FILE_MODE_READ);
   if (ef)
     {
	for (i = 0; i < items_num; i++)
	  {
	     int w, h, alpha, compress, quality, lossy;
	     void *data;
	     
	     if (eet_data_image_header_read(ef, items[i], &w, &h, &alpha, &compress, &quality, &lossy))
	       {
		  data = eet_data_image_read(ef, items[i], &w, &h, &alpha, &compress, &quality, &lossy);
		  if (data) free(data);
		  else
		    {
		       printf("failure reading %s (%i/%i\n", items[i], i, items_num);
		       exit(-1);
		    }
	       }
	     else
	       {
		  printf("failure reading header %s (%i/%i\n", items[i], i, items_num);
		  exit(-1);
	       }
	  }
     }
   eet_close(ef);
   t2 = get_time();
   printf("1 open/close: %i img headers + data in %3.3f sec (%3.3f img/sec)\n",
	  items_num,
	  t2 - t1,
	  (double)items_num / (t2 - t1));
   t1 = get_time();
   for (i = 0; i < items_num; i++)
     {
	int w, h, alpha, compress, quality, lossy;
	void *data;
	
	ef = eet_open(file, EET_FILE_MODE_READ);
	if (ef)
	  {
	     if (eet_data_image_header_read(ef, items[i], &w, &h, &alpha, &compress, &quality, &lossy))
	       {
		  data = eet_data_image_read(ef, items[i], &w, &h, &alpha, &compress, &quality, &lossy);
		  if (data) free(data);
		  else
		    {
		       printf("failure reading %s (%i/%i\n", items[i], i, items_num);
		       exit(-1);
		    }
	       }
	     else
	       {
		  printf("failure reading header %s (%i/%i\n", items[i], i, items_num);
		  exit(-1);
	       }
	     eet_close(ef);
	  }
     }
   t2 = get_time();
   printf("many open/close: %i img headers + data in %3.3f sec (%3.3f img/sec)\n",
	  items_num,
	  t2 - t1,
	  (double)items_num / (t2 - t1));
   return 0;
}