b24e7fce |
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 | 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 | printf("\nchd_open() error: %s", chd_error_string(err)); |
26 | header = chd_get_header(file); |
27 | totalbytes = header->hunkbytes * header->totalhunks; |
28 | buffer = malloc(header->hunkbytes); |
29 | for (i = 0 ; i < header->totalhunks ; i++) |
30 | { |
31 | err = chd_read(file, i, buffer); |
32 | if (err) |
33 | printf("\nchd_read() error: %s", chd_error_string(err)); |
34 | } |
35 | free(buffer); |
36 | chd_close(file); |
37 | |
38 | /* Recording the end clock tick. */ |
39 | end = clock(); |
40 | |
41 | /* Calculating total time taken by the program. */ |
42 | time_taken = ((double)(end - start)) / ((double)CLOCKS_PER_SEC); |
43 | |
44 | /* Print results */ |
45 | printf("\nRead %d bytes in %lf seconds", totalbytes, time_taken); |
46 | printf("\nRate is %lf MB/s", (((double)totalbytes)/(1024*1024)) / time_taken); |
47 | printf("\n\n"); |
48 | return 0; |
49 | } |