diff options
Diffstat (limited to 'src/util/perf_malloc.c')
-rw-r--r-- | src/util/perf_malloc.c | 97 |
1 files changed, 0 insertions, 97 deletions
diff --git a/src/util/perf_malloc.c b/src/util/perf_malloc.c deleted file mode 100644 index 1c91402da..000000000 --- a/src/util/perf_malloc.c +++ /dev/null | |||
@@ -1,97 +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 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include <gauger.h> | ||
29 | |||
30 | static uint64_t | ||
31 | perf_malloc () | ||
32 | { | ||
33 | uint64_t ret; | ||
34 | |||
35 | ret = 0; | ||
36 | for (size_t i = 1; i < 1024 * 1024; i += 1024) | ||
37 | { | ||
38 | ret += i; | ||
39 | GNUNET_free (GNUNET_malloc (i)); | ||
40 | } | ||
41 | return ret; | ||
42 | } | ||
43 | |||
44 | |||
45 | static uint64_t | ||
46 | perf_realloc () | ||
47 | { | ||
48 | uint64_t ret; | ||
49 | |||
50 | ret = 0; | ||
51 | for (size_t i = 10; i < 1024 * 1024 / 5; i += 1024) | ||
52 | { | ||
53 | char *ptr; | ||
54 | |||
55 | ret += i; | ||
56 | ptr = GNUNET_malloc (i); | ||
57 | memset (ptr, 1, i); | ||
58 | ptr = GNUNET_realloc (ptr, i + 5); | ||
59 | for (size_t j = 0; j<i; j++) | ||
60 | GNUNET_assert (1 == ptr[j]); | ||
61 | memset (ptr, 6, i + 5); | ||
62 | ptr = GNUNET_realloc (ptr, i - 5); | ||
63 | for (size_t j = 0; j<i - 5; j++) | ||
64 | GNUNET_assert (6 == ptr[j]); | ||
65 | GNUNET_free (ptr); | ||
66 | } | ||
67 | return ret; | ||
68 | } | ||
69 | |||
70 | |||
71 | int | ||
72 | main (int argc, char *argv[]) | ||
73 | { | ||
74 | struct GNUNET_TIME_Absolute start; | ||
75 | uint64_t kb; | ||
76 | |||
77 | start = GNUNET_TIME_absolute_get (); | ||
78 | kb = perf_malloc (); | ||
79 | printf ("Malloc perf took %s\n", | ||
80 | GNUNET_STRINGS_relative_time_to_string ( | ||
81 | GNUNET_TIME_absolute_get_duration (start), | ||
82 | GNUNET_YES)); | ||
83 | GAUGER ("UTIL", "Allocation", | ||
84 | kb / 1024 / (1 | ||
85 | + GNUNET_TIME_absolute_get_duration | ||
86 | (start).rel_value_us / 1000LL), "kb/ms"); | ||
87 | start = GNUNET_TIME_absolute_get (); | ||
88 | kb = perf_realloc (); | ||
89 | printf ("Realloc perf took %s\n", | ||
90 | GNUNET_STRINGS_relative_time_to_string ( | ||
91 | GNUNET_TIME_absolute_get_duration (start), | ||
92 | GNUNET_YES)); | ||
93 | return 0; | ||
94 | } | ||
95 | |||
96 | |||
97 | /* end of perf_malloc.c */ | ||