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"
29 #define VERBOSE GNUNET_NO
31 #define ASSERT(x) do { if (! (x)) { printf("Error at %s:%d\n", __FILE__, __LINE__); goto FAILURE;} } while (0)
33 #define ITERATIONS 10000
37 static unsigned int found;
40 * Name of plugin under test.
42 static const char *plugin_name;
47 struct GNUNET_TIME_Absolute exp,
48 const GNUNET_HashCode * key,
51 enum GNUNET_BLOCK_Type type)
53 if ( (size == sizeof (GNUNET_HashCode)) &&
54 (0 == memcmp (data, cls, size)) )
64 const struct GNUNET_CONFIGURATION_Handle *cfg)
66 struct GNUNET_DATACACHE_Handle *h;
69 struct GNUNET_TIME_Absolute exp;
70 struct GNUNET_TIME_Absolute start;
74 h = GNUNET_DATACACHE_create (cfg,
80 "Failed to initialize datacache. Database likely not setup, skipping test.\n");
83 exp = GNUNET_TIME_absolute_get ();
85 exp.abs_value += 5 * 60 * 1000;
86 memset (&k, 0, sizeof (GNUNET_HashCode));
87 for (i = 0; i < ITERATIONS; i++)
89 if (0 == i % (ITERATIONS / 80))
90 fprintf (stderr, ".");
91 GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
92 ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h,
94 sizeof (GNUNET_HashCode),
100 fprintf (stderr, "\n");
101 fprintf (stdout, "Stored %u items in %llums\n",
103 (unsigned long long) GNUNET_TIME_absolute_get_duration(start).rel_value);
104 start = GNUNET_TIME_absolute_get ();
105 memset (&k, 0, sizeof (GNUNET_HashCode));
106 for (i = 0; i < ITERATIONS; i++)
108 if (0 == i % (ITERATIONS / 80))
109 fprintf (stderr, ".");
110 GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
111 GNUNET_DATACACHE_get (h, &k, 1+i%16,
115 fprintf (stderr, "\n");
116 fprintf (stdout, "Found %u/%u items in %llums (%u were deleted during storage processing)\n",
118 (unsigned long long) GNUNET_TIME_absolute_get_duration(start).rel_value,
121 GNUNET_DATACACHE_destroy (h);
126 GNUNET_DATACACHE_destroy (h);
132 main (int argc, char *argv[])
136 char *const xargv[] = {
145 struct GNUNET_GETOPT_CommandLineOption options[] = {
146 GNUNET_GETOPT_OPTION_END
149 GNUNET_log_setup ("perf-datacache",
156 /* determine name of plugin to use */
157 plugin_name = argv[0];
158 while (NULL != (pos = strstr(plugin_name, "_")))
160 if (NULL != (pos = strstr(plugin_name, ".")))
163 pos = (char *) plugin_name;
165 GNUNET_snprintf (cfg_name,
167 "perf_datacache_data_%s.conf",
169 if (pos != plugin_name)
171 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1,
172 xargv, "perf-datacache", "nohelp",
173 options, &run, NULL);
175 fprintf (stderr, "Missed some perfcases: %d\n", ok);
179 /* end of perf_datacache.c */