paragraph for gnunet devs that don't know how to use the web
[oweals/gnunet.git] / src / util / perf_crypto_hash.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2002, 2003, 2004, 2006 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your 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      Affero General Public License for more details.
14     
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /**
20  * @author Christian Grothoff
21  * @file util/perf_crypto_hash.c
22  * @brief measure performance of hash function
23  */
24 #include "platform.h"
25 #include "gnunet_util_lib.h"
26 #include <gauger.h>
27 #include <gcrypt.h>
28
29
30 static void
31 perfHash ()
32 {
33   struct GNUNET_HashCode hc;
34   unsigned int i;
35   char buf[64 * 1024];
36
37   memset (buf, 1, sizeof (buf));
38   for (i = 0; i < 1024; i++)
39     GNUNET_CRYPTO_hash (buf, sizeof (buf), &hc);
40 }
41
42
43 static void
44 perfHashSmall ()
45 {
46   struct GNUNET_HashCode hc;
47   unsigned int i;
48   char buf[64];
49
50   memset (buf, 1, sizeof (buf));
51   for (i = 0; i < 1024; i++)
52     GNUNET_CRYPTO_hash (buf, sizeof (buf), &hc);
53 }
54
55
56 static void
57 perfHKDF ()
58 {
59   unsigned int i;
60   char res[128];
61   char buf[128];
62   char skm[64];
63
64   memset (buf, 1, sizeof (buf));
65   memset (skm, 2, sizeof (skm));
66   for (i = 0; i < 1024; i++)
67     GNUNET_CRYPTO_hkdf (res, sizeof (res),
68                         GCRY_MD_SHA512, GCRY_MD_SHA256,
69                         buf, sizeof (buf),
70                         skm, sizeof (skm),
71                         "test", (size_t) 4,
72                         NULL, 0);
73 }
74
75
76 int
77 main (int argc, char *argv[])
78 {
79   struct GNUNET_TIME_Absolute start;
80
81   start = GNUNET_TIME_absolute_get ();
82   perfHashSmall ();
83   printf ("1024x 64-byte Hash perf took %s\n",
84           GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
85                                                   GNUNET_YES));
86
87   start = GNUNET_TIME_absolute_get ();
88   perfHash ();
89   printf ("1024x 64k Hash perf took %s\n",
90           GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
91                                                   GNUNET_YES));
92   GAUGER ("UTIL", "Cryptographic hashing",
93           64 * 1024 / (1 +
94                        GNUNET_TIME_absolute_get_duration
95                        (start).rel_value_us / 1000LL), "kb/ms");
96   start = GNUNET_TIME_absolute_get ();
97   perfHKDF ();
98   printf ("HKDF perf took %s\n",
99           GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (start),
100                                                   GNUNET_YES));
101   GAUGER ("UTIL", "Cryptographic HKDF",
102           64 * 1024 / (1 +
103                        GNUNET_TIME_absolute_get_duration
104                        (start).rel_value_us / 1000LL), "kb/ms");
105   return 0;
106 }
107
108 /* end of perf_crypto_hash.c */