2 This file is part of GNUnet.
3 (C) 2006, 2009 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;
41 struct GNUNET_TIME_Absolute exp,
42 const GNUNET_HashCode * key,
45 enum GNUNET_BLOCK_Type type)
47 if ( (size == sizeof (GNUNET_HashCode)) &&
48 (0 == memcmp (data, cls, size)) )
56 struct GNUNET_SCHEDULER_Handle *sched,
59 const struct GNUNET_CONFIGURATION_Handle *cfg)
61 struct GNUNET_DATACACHE_Handle *h;
64 struct GNUNET_TIME_Absolute exp;
65 struct GNUNET_TIME_Absolute start;
69 h = GNUNET_DATACACHE_create (sched,
74 exp = GNUNET_TIME_absolute_get ();
76 exp.value += 5 * 60 * 1000;
77 memset (&k, 0, sizeof (GNUNET_HashCode));
78 for (i = 0; i < ITERATIONS; i++)
80 if (0 == i % (ITERATIONS / 80))
81 fprintf (stderr, ".");
82 GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
83 ASSERT (GNUNET_OK == GNUNET_DATACACHE_put (h,
85 sizeof (GNUNET_HashCode),
91 fprintf (stderr, "\n");
92 fprintf (stdout, "Stored %u items in %llums\n",
94 (unsigned long long) GNUNET_TIME_absolute_get_duration(start).value);
95 start = GNUNET_TIME_absolute_get ();
96 memset (&k, 0, sizeof (GNUNET_HashCode));
97 for (i = 0; i < ITERATIONS; i++)
99 if (0 == i % (ITERATIONS / 80))
100 fprintf (stderr, ".");
101 GNUNET_CRYPTO_hash (&k, sizeof (GNUNET_HashCode), &n);
102 GNUNET_DATACACHE_get (h, &k, 1+i%16,
106 fprintf (stderr, "\n");
107 fprintf (stdout, "Found %u/%u items in %llums (%u were deleted during storage processing)\n",
109 (unsigned long long) GNUNET_TIME_absolute_get_duration(start).value,
112 GNUNET_DATACACHE_destroy (h);
117 GNUNET_DATACACHE_destroy (h);
125 char *const argv[] = { "perf-datacache-api",
127 "perf_datacache_data.conf",
133 struct GNUNET_GETOPT_CommandLineOption options[] = {
134 GNUNET_GETOPT_OPTION_END
136 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
137 argv, "perf-datacache-api", "nohelp",
138 options, &run, NULL);
140 fprintf (stderr, "Missed some perfcases: %d\n", ok);
146 main (int argc, char *argv[])
150 GNUNET_DISK_directory_remove ("/tmp/perf-gnunetd-datacache");
151 GNUNET_log_setup ("perf-datacache-api",
163 /* end of perf_datacache.c */