Initial commit to Gerrit
[profile/ivi/orc.git] / testsuite / perf_parse_compare.c
1
2 #include <orc/orc.h>
3 #include <orc-test/orctest.h>
4 #include <orc/orcparse.h>
5
6 #include <stdio.h>
7 #include <stdlib.h>
8
9 static char * read_file (const char *filename);
10 void output_code (OrcProgram *p, FILE *output);
11 void output_code_header (OrcProgram *p, FILE *output);
12 void output_code_test (OrcProgram *p, FILE *output);
13
14 int error = FALSE;
15
16 int
17 main (int argc, char *argv[])
18 {
19   char *code;
20   int n;
21   int i;
22   OrcProgram **programs;
23   const char *filename = NULL;
24
25   orc_init ();
26   orc_test_init ();
27
28   if (argc >= 2) {
29     filename = argv[1];
30   }
31   if (filename == NULL) {
32     filename = getenv ("testfile");
33   }
34   if (filename == NULL) {
35     filename = "test.orc";
36   }
37   code = read_file (filename);
38   if (!code) {
39     printf("perf_parse <file.orc>\n");
40     exit(1);
41   }
42
43   n = orc_parse (code, &programs);
44
45   for(i=0;i<n;i++){
46     double perf_mmx;
47     double perf_sse;
48     perf_mmx = orc_test_performance_full (programs[i], 0, "mmx");
49     perf_sse = orc_test_performance_full (programs[i], 0, "sse");
50     printf("%g %g\n", perf_mmx, perf_sse);
51   }
52
53   if (error) return 1;
54   return 0;
55 }
56
57
58 static char *
59 read_file (const char *filename)
60 {
61   FILE *file = NULL;
62   char *contents = NULL;
63   long size;
64   int ret;
65
66   file = fopen (filename, "r");
67   if (file == NULL) return NULL;
68
69   ret = fseek (file, 0, SEEK_END);
70   if (ret < 0) goto bail;
71
72   size = ftell (file);
73   if (size < 0) goto bail;
74
75   ret = fseek (file, 0, SEEK_SET);
76   if (ret < 0) goto bail;
77
78   contents = malloc (size + 1);
79   if (contents == NULL) goto bail;
80
81   ret = fread (contents, size, 1, file);
82   if (ret < 0) goto bail;
83
84   contents[size] = 0;
85
86   return contents;
87 bail:
88   /* something failed */
89   if (file) fclose (file);
90   if (contents) free (contents);
91
92   return NULL;
93 }
94