2 This file is part of GNUnet.
3 (C) 2006, 2009, 2010 Christian Grothoff (and other contributing authors)
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.
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.
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.
21 * @file datacache/perf_datacache.c
22 * @brief Performance evaluation for the datacache implementations.
26 #include "gnunet_util_lib.h"
27 #include "gnunet_datacache_lib.h"
30 #define VERBOSE GNUNET_NO
32 #define ASSERT(x) do { if (! (x)) { printf("Error at %s:%d\n", __FILE__, __LINE__); goto FAILURE;} } while (0)
34 #define ITERATIONS 10000
38 static unsigned int found;
41 * Name of plugin under test.
43 static const char *plugin_name;
48 struct GNUNET_TIME_Absolute exp,
49 const GNUNET_HashCode * key,
52 enum GNUNET_BLOCK_Type type)
54 if ( (size == sizeof (GNUNET_HashCode)) &&
55 (0 == memcmp (data, cls, size)) )
65 const struct GNUNET_CONFIGURATION_Handle *cfg)
67 struct GNUNET_DATACACHE_Handle *h;
70 struct GNUNET_TIME_Absolute exp;
71 struct GNUNET_TIME_Absolute start;
76 h = GNUNET_DATACACHE_create (cfg,
82 "Failed to initialize datacache. Database likely not setup, skipping test.\n");
85 exp = GNUNET_TIME_absolute_get ();
87 exp.abs_value += 5 * 60 * 1000;
88 memset (&k, 0, sizeof (GNUNET_HashCode));
89 for (i = 0; i < ITERATIONS; i++)
91 if (0 == i % (ITERATIONS / 80))
92 fprintf (stderr, ".");
93 GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
94 ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h,
96 sizeof (GNUNET_HashCode),
102 fprintf (stderr, "\n");
103 fprintf (stdout, "Stored %u items in %llums\n",
105 (unsigned long long) GNUNET_TIME_absolute_get_duration(start).rel_value);
106 GNUNET_snprintf (gstr, sizeof (gstr),
110 "Time to PUT item in datacache",
111 GNUNET_TIME_absolute_get_duration(start).rel_value / ITERATIONS,
113 start = GNUNET_TIME_absolute_get ();
114 memset (&k, 0, sizeof (GNUNET_HashCode));
115 for (i = 0; i < ITERATIONS; i++)
117 if (0 == i % (ITERATIONS / 80))
118 fprintf (stderr, ".");
119 GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
120 GNUNET_DATACACHE_get (h, &k, 1+i%16,
124 fprintf (stderr, "\n");
126 "Found %u/%u items in %llums (%u were deleted during storage processing)\n",
128 (unsigned long long) GNUNET_TIME_absolute_get_duration(start).rel_value,
132 "Time to GET item from datacache",
133 GNUNET_TIME_absolute_get_duration(start).rel_value / found, "ms/item");
134 GNUNET_DATACACHE_destroy (h);
139 GNUNET_DATACACHE_destroy (h);
145 main (int argc, char *argv[])
149 char *const xargv[] = {
158 struct GNUNET_GETOPT_CommandLineOption options[] = {
159 GNUNET_GETOPT_OPTION_END
162 GNUNET_log_setup ("perf-datacache",
169 /* determine name of plugin to use */
170 plugin_name = argv[0];
171 while (NULL != (pos = strstr(plugin_name, "_")))
173 if (NULL != (pos = strstr(plugin_name, ".")))
176 pos = (char *) plugin_name;
178 GNUNET_snprintf (cfg_name,
180 "perf_datacache_data_%s.conf",
182 if (pos != plugin_name)
184 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
185 xargv, "perf-datacache", "nohelp",
186 options, &run, NULL);
188 fprintf (stderr, "Missed some perfcases: %d\n", ok);
192 /* end of perf_datacache.c */