Imported Upstream version 4.6.0
[debian/atlc] / tests / benchmark.c
1 /*
2 atlc - arbitrary transmission line calculator, for the analysis of
3 transmission lines are directional couplers. 
4
5 Copyright (C) 2002. Dr. David Kirkby, PhD (G8WRB).
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either package_version 2
10 of the License, or (at your option) any later package_version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
20 USA.
21
22 Dr. David Kirkby, e-mail drkirkby@ntlworld.com 
23
24 */
25 /* Times two commands entered on the command line, to make
26 sure the second takes less time than the first. */
27
28 #include "config.h"
29
30 #ifdef HAVE_STDIO_H
31 #include <stdio.h>
32 #endif
33
34 #ifdef HAVE_STDLIB_H
35 #include <stdlib.h>
36 #endif
37
38 #ifdef HAVE_SYS_TYPES_H
39 #include <sys/types.h>
40 #endif
41
42 #ifdef HAVE_TIME_H
43 #include <time.h>
44 #endif  
45
46 #ifdef HAVE_STRING_H
47 #include <string.h>
48 #endif  
49
50 #ifdef HAVE_UNISTD_H
51 #include <unistd.h> /* sleep on Solaris needs this */
52 #endif
53
54 #include "defs.h"
55
56
57 int main(int argc, char **argv)
58 {
59   time_t start1, finished1;
60   struct computer_data data;
61
62   char *str;
63   FILE *fp;
64
65 #ifdef ENABLE_POSIX_THREADS
66   time_t start2, finished2;
67   strcpy((char *) data.eff,"unknown");
68 #else
69   strcpy((char *) data.eff,"N/A");
70 #endif /* ENABLE_POSIX_THREADS */
71
72   strcpy((char *) data.mhz,"unknown");
73   strcpy((char *) data.cpu_type,"unknown");
74   strcpy((char *) data.fpu_type,"unknown");
75   strcpy((char *) data.max_cpus,"unknown");
76   strcpy((char *) data.cpus,"unknown");
77   strcpy((char *) data.memory,"unknown");
78   strcpy((char *) data.sysname,"unknown");
79   strcpy((char *) data.nodename,"unknown");
80   strcpy((char *) data.release,"unknown");
81   strcpy((char *) data.version,"unknown");
82   strcpy((char *) data.machine,"unknown");
83   strcpy((char *) data.hw_provider,"unknown");
84   strcpy((char *) data.hw_platform,"unknown");
85   strcpy((char *) data.speedup,"N/A    ");
86   strcpy((char *) data.t2,"N/A    ");
87   strcpy((char *) data.L1data,"unknown");
88   strcpy((char *) data.L1instruction,"unknown");
89   strcpy((char *) data.L2,"unknown");
90
91 /* Trying to get information about the hardware is likely to break
92 on some platforms, as it is very platform specific. If the option 
93 --disble-hardware-info is given, the software will not try to obtain
94 such information. 
95
96 The information is useful, for benchmarking purposes and to 
97 obtain the efficiency of a multi-processor machine if the number
98 of CPUs can be found. */
99
100 #ifdef TRY_TO_GET_HARDWARE_INFO 
101   try_portable(&data);  /* Use uname, which is platform independant */
102
103   try_aix(&data);      /* Try to find if the system is AIX and if so get data */
104   try_bsd(&data); 
105   try_hpux(&data);
106   try_irix(&data);
107   try_linux(&data); 
108   try_solaris(&data);
109   try_tru64(&data); 
110   try_unicos(&data); 
111 #endif
112
113
114 /* Whatever happens (single-threaded or multi-theraded, we will check that all the 
115 files (the executable atlc and bitmap are both present). */
116   if(argc !=3 )
117   {
118     fprintf(stderr,"Usage: path_to_atlc path_to_bitmap\n");
119     exit(1);
120   }
121   if( (str=malloc(2000)) == NULL) 
122   {
123     fprintf(stderr,"Memory allocation failure in benchmark.c\n");
124     exit(1);
125   }
126   if ((fp=fopen(argv[1],"rb")) == NULL)
127   {
128     fprintf(stderr,"Can't open the binary file %s for reading\n",argv[1]);
129     exit(2);
130   }
131   if ((fp=fopen(argv[2],"rb")) == NULL)
132   {
133     fprintf(stderr,"Can't open the bitmap %s for reading\n",argv[2]);
134     exit(3);
135   }
136 /* Assuming we have not exited due to a lack of suitable files present, 
137 run the benchmark at least once - but possibly twice if code is   
138 multi-threaded */
139
140   sprintf(str,"%s -s -S -t0 %s > /dev/null 2> /dev/null \n", argv[1], argv[2]);
141   time(&start1);
142   pclose(popen(str, "w"));
143   time(&finished1);
144   sprintf(data.t1,"%d",(int) (finished1-start1));
145
146 /* If the code is multi-threaded, run the benchmark for a second time. We can
147 always calculate a speedup in these circumstances */
148
149 #ifdef ENABLE_POSIX_THREADS
150   sprintf(str,"%s -s -S %s > /dev/null\n", argv[1], argv[2]);
151   time(&start2);
152   pclose(popen(str, "w"));
153   time(&finished2);
154   sprintf(data.t2,"%d",(int) (finished2-start2));
155   sprintf(data.speedup,"%.3f\n",atof(data.t1)/atof(data.t2)); /* other N/A */
156
157   /* Whether or not we can calculate the efficency depends on whether we have managed
158   to obtain the number of processors present in the system. If the number of procesors
159   found is zero (i.e. we have been unable to determine them, due to a lack of
160   processor_information, or that not working properly, then we can't compute the efficiency,
161   so will leave it at the default value of "unknown". */
162
163   if(atoi(data.cpus) != 0)
164     sprintf(data.eff,"%.3f",atof(data.speedup)/atoi(data.cpus)); /* otherwise unknown */
165 #endif
166   printf("0 %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s %s\n",data.t1, data.t2, data.speedup, data.cpus, data.mhz, data.eff, data.cpu_type,data.fpu_type,data.max_cpus,data.memory,data.sysname,data.nodename,data.release,data.version,data.machine,data.hw_provider, data.hw_platform, data.L1data, data.L1instruction, data.L2);
167   return(0);
168 }
169
170