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"
28 #include "gnunet_testing_lib-new.h"
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;
47 checkIt (void *cls, struct GNUNET_TIME_Absolute exp,
48 const struct GNUNET_HashCode * key, size_t size, const char *data,
49 enum GNUNET_BLOCK_Type type)
51 if ((size == sizeof (struct GNUNET_HashCode)) && (0 == memcmp (data, cls, size)))
58 run (void *cls, char *const *args, const char *cfgfile,
59 const struct GNUNET_CONFIGURATION_Handle *cfg)
61 struct GNUNET_DATACACHE_Handle *h;
62 struct GNUNET_HashCode k;
63 struct GNUNET_HashCode n;
64 struct GNUNET_TIME_Absolute exp;
65 struct GNUNET_TIME_Absolute start;
70 h = GNUNET_DATACACHE_create (cfg, "perfcache");
74 FPRINTF (stderr, "%s", "Failed to initialize datacache. Database likely not setup, skipping test.\n");
77 exp = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS);
78 start = GNUNET_TIME_absolute_get ();
79 memset (&k, 0, sizeof (struct GNUNET_HashCode));
80 for (i = 0; i < ITERATIONS; i++)
82 if (0 == i % (ITERATIONS / 80))
83 FPRINTF (stderr, "%s", ".");
84 GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n);
86 GNUNET_DATACACHE_put (h, &k, sizeof (struct GNUNET_HashCode),
87 (const char *) &n, 1 + i % 16, exp));
90 FPRINTF (stderr, "%s", "\n");
91 FPRINTF (stdout, "Stored %u items in %s\n", ITERATIONS,
92 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES));
93 GNUNET_snprintf (gstr, sizeof (gstr), "DATACACHE-%s", plugin_name);
94 GAUGER (gstr, "Time to PUT item in datacache",
95 GNUNET_TIME_absolute_get_duration (start).rel_value / ITERATIONS,
97 start = GNUNET_TIME_absolute_get ();
98 memset (&k, 0, sizeof (struct GNUNET_HashCode));
99 for (i = 0; i < ITERATIONS; i++)
101 if (0 == i % (ITERATIONS / 80))
102 FPRINTF (stderr, "%s", ".");
103 GNUNET_CRYPTO_hash (&k, sizeof (struct GNUNET_HashCode), &n);
104 GNUNET_DATACACHE_get (h, &k, 1 + i % 16, &checkIt, &n);
107 FPRINTF (stderr, "%s", "\n");
109 "Found %u/%u items in %s (%u were deleted during storage processing)\n",
111 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start), GNUNET_YES),
114 GAUGER (gstr, "Time to GET item from datacache",
115 GNUNET_TIME_absolute_get_duration (start).rel_value / found,
117 GNUNET_DATACACHE_destroy (h);
122 GNUNET_DATACACHE_destroy (h);
128 main (int argc, char *argv[])
131 char *const xargv[] = {
137 struct GNUNET_GETOPT_CommandLineOption options[] = {
138 GNUNET_GETOPT_OPTION_END
141 GNUNET_log_setup ("perf-datacache",
144 plugin_name = GNUNET_TESTING_get_testname_from_underscore (argv[0]);
145 GNUNET_snprintf (cfg_name, sizeof (cfg_name), "perf_datacache_data_%s.conf",
147 GNUNET_PROGRAM_run ((sizeof (xargv) / sizeof (char *)) - 1, xargv,
148 "perf-datacache", "nohelp", options, &run, NULL);
150 FPRINTF (stderr, "Missed some perfcases: %d\n", ok);
154 /* end of perf_datacache.c */