missed one!
[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.sysname,"unknown");
78   strcpy((char *) data.nodename,"unknown");
79   strcpy((char *) data.release,"unknown");
80   strcpy((char *) data.version,"unknown");
81   strcpy((char *) data.machine,"unknown");
82   strcpy((char *) data.hw_provider,"unknown");
83   strcpy((char *) data.hw_platform,"unknown");
84   strcpy((char *) data.speedup,"N/A    ");
85   strcpy((char *) data.t2,"N/A    ");
86   strcpy((char *) data.L1data,"unknown");
87   strcpy((char *) data.L1instruction,"unknown");
88   strcpy((char *) data.L2,"unknown");
89
90 /* Trying to get information about the hardware is likely to break
91 on some platforms, as it is very platform specific. If the option 
92 --disble-hardware-info is given, the software will not try to obtain
93 such information. 
94
95 The information is useful, for benchmarking purposes and to 
96 obtain the efficiency of a multi-processor machine if the number
97 of CPUs can be found. */
98
99 #ifdef TRY_TO_GET_HARDWARE_INFO 
100   try_portable(&data);  /* Use uname, which is platform independant */
101
102   try_aix(&data);      /* Try to find if the system is AIX and if so get data */
103   try_bsd(&data); 
104   try_hpux(&data);
105   try_irix(&data);
106   try_linux(&data); 
107   try_solaris(&data);
108   try_tru64(&data); 
109   try_unicos(&data); 
110 #endif
111
112
113 /* Whatever happens (single-threaded or multi-theraded, we will check that all the 
114 files (the executable atlc and bitmap are both present). */
115   if(argc !=3 )
116   {
117     fprintf(stderr,"Usage: path_to_atlc path_to_bitmap\n");
118     exit(1);
119   }
120   if( (str=malloc(2000)) == NULL) 
121   {
122     fprintf(stderr,"Memory allocation failure in benchmark.c\n");
123     exit(1);
124   }
125   if ((fp=fopen(argv[1],"rb")) == NULL)
126   {
127     fprintf(stderr,"Can't open the binary file %s for reading\n",argv[1]);
128     exit(2);
129   }
130   if ((fp=fopen(argv[2],"rb")) == NULL)
131   {
132     fprintf(stderr,"Can't open the bitmap %s for reading\n",argv[2]);
133     exit(3);
134   }
135 /* Assuming we have not exited due to a lack of suitable files present, 
136 run the benchmark at least once - but possibly twice if code is   
137 multi-threaded */
138
139   sprintf(str,"%s -s -S -t0 %s > /dev/null 2> /dev/null \n", argv[1], argv[2]);
140   time(&start1);
141   pclose(popen(str, "w"));
142   time(&finished1);
143   sprintf(data.t1,"%d",(int) (finished1-start1));
144
145 /* If the code is multi-threaded, run the benchmark for a second time. We can
146 always calculate a speedup in these circumstances */
147
148 #ifdef ENABLE_POSIX_THREADS
149   sprintf(str,"%s -s -S %s > /dev/null\n", argv[1], argv[2]);
150   time(&start2);
151   pclose(popen(str, "w"));
152   time(&finished2);
153   sprintf(data.t2,"%d",(int) (finished2-start2));
154   sprintf(data.speedup,"%.3f\n",atof(data.t1)/atof(data.t2)); /* other N/A */
155
156   /* Whether or not we can calculate the efficency depends on whether we have managed
157   to obtain the number of processors present in the system. If the number of procesors
158   found is zero (i.e. we have been unable to determine them, due to a lack of
159   processor_information, or that not working properly, then we can't compute the efficiency,
160   so will leave it at the default value of "unknown". */
161
162   if(atoi(data.cpus) != 0)
163     sprintf(data.eff,"%.3f",atof(data.speedup)/atoi(data.cpus)); /* otherwise unknown */
164 #endif
165   printf("0 %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.sysname,data.nodename,data.release,data.version,data.machine,data.hw_provider, data.hw_platform, data.L1data, data.L1instruction, data.L2);
166   return(0);
167 }
168
169