update libchdr
[pcsx_rearmed.git] / deps / libchdr / tests / benchmark.c
1 #include <libchdr/chd.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <time.h>
5
6 int main(int argc, char** argv)
7 {
8   chd_error err;
9   chd_file* file;
10   const chd_header* header;
11   void* buffer;
12   unsigned int i;
13   unsigned int totalbytes;
14   clock_t start, end;
15   double time_taken;
16
17   printf("\nlibchdr benchmark tool....");
18
19   /* Recording the starting clock tick.*/
20   start = clock(); 
21   
22   /* Sequential read all hunks */
23   err = chd_open(argv[1], CHD_OPEN_READ, NULL, &file);
24   if (err)
25   {
26     printf("\nchd_open() error: %s", chd_error_string(err));
27     return 0;
28   }
29   header = chd_get_header(file);
30   totalbytes = header->hunkbytes * header->totalhunks;
31   buffer = malloc(header->hunkbytes);
32   for (i = 0 ; i < header->totalhunks ; i++)
33   {
34     err = chd_read(file, i, buffer);
35     if (err)
36       printf("\nchd_read() error: %s", chd_error_string(err));
37   }
38   free(buffer);
39   chd_close(file);
40
41   /* Recording the end clock tick. */
42   end = clock();
43
44   /* Calculating total time taken by the program. */
45   time_taken = ((double)(end - start)) / ((double)CLOCKS_PER_SEC);
46
47   /* Print results */
48   printf("\nRead %d bytes in %lf seconds", totalbytes, time_taken);
49   printf("\nRate is %lf MB/s", (((double)totalbytes)/(1024*1024)) / time_taken);
50   printf("\n\n");
51   return 0;
52 }