aboutsummaryrefslogtreecommitdiff
path: root/src/util/perf_malloc.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2023-10-18 13:37:38 +0200
committerMartin Schanzenbach <schanzen@gnunet.org>2023-10-18 13:37:38 +0200
commit9ef4abad615bea12d13be542b8ae5fbeb2dfee32 (patch)
tree8875a687e004d331c9ea6a1d511a328c72b88113 /src/util/perf_malloc.c
parente95236b3ed78cd597c15f34b89385295702b627f (diff)
downloadgnunet-9ef4abad615bea12d13be542b8ae5fbeb2dfee32.tar.gz
gnunet-9ef4abad615bea12d13be542b8ae5fbeb2dfee32.zip
NEWS: Refactoring components under src/ into lib/, plugin/, cli/ and service/
This also includes a necessary API refactoring of crypto from IDENTITY to UTIL.
Diffstat (limited to 'src/util/perf_malloc.c')
-rw-r--r--src/util/perf_malloc.c98
1 files changed, 0 insertions, 98 deletions
diff --git a/src/util/perf_malloc.c b/src/util/perf_malloc.c
deleted file mode 100644
index 48a4a2ae7..000000000
--- a/src/util/perf_malloc.c
+++ /dev/null
@@ -1,98 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012 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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @author Christian Grothoff
23 * @file util/perf_malloc.c
24 * @brief measure performance of allocation functions
25 */
26
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include <gauger.h>
30
31static uint64_t
32perf_malloc ()
33{
34 uint64_t ret;
35
36 ret = 0;
37 for (size_t i = 1; i < 1024 * 1024; i += 1024)
38 {
39 ret += i;
40 GNUNET_free_nz (GNUNET_malloc (i));
41 }
42 return ret;
43}
44
45
46static uint64_t
47perf_realloc ()
48{
49 uint64_t ret;
50
51 ret = 0;
52 for (size_t i = 10; i < 1024 * 1024 / 5; i += 1024)
53 {
54 char *ptr;
55
56 ret += i;
57 ptr = GNUNET_malloc (i);
58 memset (ptr, 1, i);
59 ptr = GNUNET_realloc (ptr, i + 5);
60 for (size_t j = 0; j<i; j++)
61 GNUNET_assert (1 == ptr[j]);
62 memset (ptr, 6, i + 5);
63 ptr = GNUNET_realloc (ptr, i - 5);
64 for (size_t j = 0; j<i - 5; j++)
65 GNUNET_assert (6 == ptr[j]);
66 GNUNET_free (ptr);
67 }
68 return ret;
69}
70
71
72int
73main (int argc, char *argv[])
74{
75 struct GNUNET_TIME_Absolute start;
76 uint64_t kb;
77
78 start = GNUNET_TIME_absolute_get ();
79 kb = perf_malloc ();
80 printf ("Malloc perf took %s\n",
81 GNUNET_STRINGS_relative_time_to_string (
82 GNUNET_TIME_absolute_get_duration (start),
83 GNUNET_YES));
84 GAUGER ("UTIL", "Allocation",
85 kb / 1024 / (1
86 + GNUNET_TIME_absolute_get_duration
87 (start).rel_value_us / 1000LL), "kb/ms");
88 start = GNUNET_TIME_absolute_get ();
89 kb = perf_realloc ();
90 printf ("Realloc perf took %s\n",
91 GNUNET_STRINGS_relative_time_to_string (
92 GNUNET_TIME_absolute_get_duration (start),
93 GNUNET_YES));
94 return 0;
95}
96
97
98/* end of perf_malloc.c */