aboutsummaryrefslogtreecommitdiff
path: root/src/ats-test/perf_transport_ats.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats-test/perf_transport_ats.c')
-rw-r--r--src/ats-test/perf_transport_ats.c337
1 files changed, 337 insertions, 0 deletions
diff --git a/src/ats-test/perf_transport_ats.c b/src/ats-test/perf_transport_ats.c
new file mode 100644
index 000000000..0be15d255
--- /dev/null
+++ b/src/ats-test/perf_transport_ats.c
@@ -0,0 +1,337 @@
1/*
2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/**
21 * @file transport/perf_transport_ats.c
22 * @brief testcase for ats functionality
23 */
24#include "platform.h"
25#include "gnunet_time_lib.h"
26#include "gauger.h"
27#include <glpk.h>
28
29#define VERBOSE GNUNET_NO
30
31#define EXECS 5
32
33static int ret = 0;
34
35static int executions = EXECS;
36static uint64_t exec_time[EXECS];
37
38static uint64_t sim_no_opt_avg;
39static uint64_t sim_with_opt_avg;
40static uint64_t mlp_no_opt_avg;
41static uint64_t mlp_with_opt_avg;
42
43static glp_prob *prob;
44
45static struct GNUNET_TIME_Absolute start;
46static struct GNUNET_TIME_Absolute end;
47
48static void
49solve_mlp (int presolve)
50{
51 int result, solution;
52 glp_iocp opt_mlp;
53
54 glp_init_iocp (&opt_mlp);
55 opt_mlp.msg_lev = GLP_MSG_OFF;
56 opt_mlp.presolve = GLP_OFF;
57
58 result = glp_intopt (prob, &opt_mlp);
59 solution = glp_mip_status (prob);
60 GNUNET_assert ((solution == 5) && (result == 0));
61}
62
63static void
64solve_lp (int presolve)
65{
66 int result;
67 int solution;
68
69 glp_smcp opt_lp;
70
71 glp_init_smcp (&opt_lp);
72
73 opt_lp.msg_lev = GLP_MSG_OFF;
74 if (presolve == GNUNET_YES)
75 opt_lp.presolve = GLP_ON;
76 else
77 opt_lp.presolve = GLP_OFF;
78
79 result = glp_simplex (prob, &opt_lp);
80 solution = glp_get_status (prob);
81 GNUNET_assert ((solution == 5) && (result == 0));
82}
83
84#if 0
85/* Modify quality constraint */
86static void
87modify_qm (int start, int length, int values_to_change)
88{
89 //int * ind = GNUNET_malloc (length * sizeof (int));
90 //double *val = GNUNET_malloc (length * sizeof (double));
91 int ind[1000];
92 double val[1000];
93
94 int res = 0;
95 int c = start, c2 = 1;
96
97 while (c <= (start + values_to_change))
98 {
99 res = glp_get_mat_row (prob, c, ind, val);
100
101 printf ("%i %i \n", c, res);
102 for (c2 = 0; c2 < res; c2++)
103 {
104 printf ("%i = %f \n", ind[c2], val[c2]);
105 }
106 c++;
107 }
108 //glp_set_mat_row(prob, start, length, ind, val);
109}
110#endif
111
112
113
114static void
115bench_simplex_optimization (char *file, int executions)
116{
117 int c;
118 int res;
119
120 prob = glp_create_prob ();
121 res = glp_read_lp (prob, NULL, file);
122 if (res != 0)
123 {
124 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem file `%s' not found\n", file);
125 ret = 1;
126 return;
127 }
128
129 solve_lp (GNUNET_YES);
130
131 for (c = 0; c < executions; c++)
132 {
133 start = GNUNET_TIME_absolute_get ();
134 solve_lp (GNUNET_NO);
135 end = GNUNET_TIME_absolute_get ();
136
137 exec_time[c] = GNUNET_TIME_absolute_get_difference (start, end).rel_value;
138
139 sim_with_opt_avg += exec_time[c];
140 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
141 "Simplex /w optimization iterations %i: %llu \n", c,
142 exec_time[c]);
143 }
144
145 glp_delete_prob (prob);
146}
147
148
149static void
150bench_simplex_no_optimization (char *file, int executions)
151{
152 int c;
153 int res;
154
155 prob = glp_create_prob ();
156 res = glp_read_lp (prob, NULL, file);
157 if (res != 0)
158 {
159 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem file `%s' not found\n", file);
160 ret = 1;
161 return;
162 }
163
164 for (c = 0; c < executions; c++)
165 {
166 start = GNUNET_TIME_absolute_get ();
167 solve_lp (GNUNET_YES);
168 end = GNUNET_TIME_absolute_get ();
169
170 exec_time[c] = GNUNET_TIME_absolute_get_difference (start, end).rel_value;
171
172 sim_no_opt_avg += exec_time[c];
173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Simplex iterations %i: %llu \n", c,
174 exec_time[c]);
175 }
176
177 glp_delete_prob (prob);
178}
179
180static void
181bench_mlp_no_optimization (char *file, int executions)
182{
183 int c;
184 int res;
185
186 prob = glp_create_prob ();
187 res = glp_read_lp (prob, NULL, file);
188 if (res != 0)
189 {
190 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem file `%s' not found\n", file);
191 ret = 1;
192 return;
193 }
194 for (c = 0; c < executions; c++)
195 {
196 start = GNUNET_TIME_absolute_get ();
197 solve_lp (GNUNET_YES);
198 solve_mlp (GNUNET_NO);
199 end = GNUNET_TIME_absolute_get ();
200
201 exec_time[c] = GNUNET_TIME_absolute_get_difference (start, end).rel_value;
202
203 mlp_no_opt_avg += exec_time[c];
204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
205 "MLP iterations no optimization %i: %llu \n", c, exec_time[c]);
206 }
207
208 glp_delete_prob (prob);
209}
210
211
212static void
213bench_mlp_with_optimization (char *file, int executions, int changes)
214{
215 int c;
216 int res;
217
218 prob = glp_create_prob ();
219 res = glp_read_lp (prob, NULL, file);
220 if (res != 0)
221 {
222 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem file `%s' not found\n", file);
223 ret = 1;
224 return;
225 }
226
227 solve_lp (GNUNET_YES);
228
229 for (c = 0; c < executions; c++)
230 {
231 start = GNUNET_TIME_absolute_get ();
232 //modify_qm(906, 0, 0);
233 solve_lp (GNUNET_NO);
234 solve_mlp (GNUNET_NO);
235 end = GNUNET_TIME_absolute_get ();
236
237 exec_time[c] = GNUNET_TIME_absolute_get_difference (start, end).rel_value;
238
239 mlp_with_opt_avg += exec_time[c];
240 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
241 "MLP /w optimization iterations %i: %llu \n", c, exec_time[c]);
242 }
243
244 glp_delete_prob (prob);
245}
246
247#if 0
248void
249modify_cr (int start, int length, int count)
250{
251 //int * ind = GNUNET_malloc (length * sizeof (int));
252 //double *val = GNUNET_malloc (length * sizeof (double));
253 int ind[500];
254 double val[500];
255 int res = 0;
256 int c = start, c2 = 1;
257
258 while (c <= (start + count))
259 {
260 res = glp_get_mat_row (prob, c, ind, val);
261
262 printf ("row index: %i non-zero elements: %i \n", c, res);
263 for (c2 = 1; c2 <= res; c2++)
264 {
265 printf ("%i = %f ", ind[c2], val[c2]);
266 }
267 c++;
268 printf ("\n----\n");
269 }
270 //glp_set_mat_row(prob, start, length, ind, val);
271}
272#endif
273
274
275int
276main (int argc, char *argv[])
277{
278
279 GNUNET_log_setup ("perf-transport-ats",
280#if VERBOSE
281 "DEBUG",
282#else
283 "INFO",
284#endif
285 NULL);
286 int nullfd = OPEN ("/dev/null", O_RDWR | O_APPEND);
287
288 if (nullfd < 0)
289 return GNUNET_SYSERR;
290 if (dup2 (nullfd, 1) < 0)
291 {
292 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "dup2");
293 (void) CLOSE (nullfd);
294 return GNUNET_SYSERR;
295 }
296
297
298 char *file = "ats_mlp_p100_m400.problem";
299
300 bench_simplex_no_optimization (file, executions);
301 bench_simplex_optimization (file, executions);
302 bench_mlp_no_optimization (file, executions);
303 bench_mlp_with_optimization (file, executions, 0);
304
305 if (ret != 0)
306 return ret;
307
308 // -> 400 addresses
309 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
310 "Simplex, no optimization, average per address: %f\n",
311 ((double) sim_no_opt_avg / EXECS) / 400);
312 GAUGER ("TRANSPORT", "GLPK simplex no optimization",
313 ((double) sim_no_opt_avg / EXECS) / 400, "ms/address");
314
315 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
316 "Simplex, with optimization, average per address: %f\n",
317 ((double) sim_with_opt_avg / EXECS) / 400);
318 GAUGER ("TRANSPORT",
319 "GLPK simplex, 100 peers 400 addresses with optimization",
320 ((double) sim_with_opt_avg / EXECS) / 400, "ms/address");
321
322 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
323 "MLP no optimization average per address: %f\n",
324 ((double) mlp_no_opt_avg / EXECS) / 400);
325 GAUGER ("TRANSPORT", "GLPK MLP 100 peers 400 addresses no optimization",
326 ((double) mlp_no_opt_avg / EXECS) / 400, "ms/address");
327
328 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
329 "MLP optimization average per address: %f\n",
330 ((double) mlp_with_opt_avg / EXECS) / 400);
331 GAUGER ("TRANSPORT", "GLPK MLP 100 peers 400 addresses with optimization",
332 ((double) mlp_with_opt_avg / EXECS) / 400, "ms/address");
333 (void) CLOSE (nullfd);
334 return ret;
335}
336
337/* end of perf_transport_ats.c*/