diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-02-04 18:45:19 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-02-04 18:45:19 +0100 |
commit | 4caa0d2907082868e32a77c5a8ebf85c527497ca (patch) | |
tree | b10737f008921d7b5122656458665981d0ed9b46 /src/util | |
parent | e14544109bf1c473a0e32d6c3b0e84dec8989efc (diff) | |
download | gnunet-4caa0d2907082868e32a77c5a8ebf85c527497ca.tar.gz gnunet-4caa0d2907082868e32a77c5a8ebf85c527497ca.zip |
add minimal scheduler benchmark
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/Makefile.am | 8 | ||||
-rw-r--r-- | src/util/perf_scheduler.c | 103 |
2 files changed, 110 insertions, 1 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index fc8f424dc..60b845414 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am | |||
@@ -245,7 +245,8 @@ if HAVE_BENCHMARKS | |||
245 | perf_crypto_paillier \ | 245 | perf_crypto_paillier \ |
246 | perf_crypto_symmetric \ | 246 | perf_crypto_symmetric \ |
247 | perf_crypto_asymmetric \ | 247 | perf_crypto_asymmetric \ |
248 | perf_malloc | 248 | perf_malloc \ |
249 | perf_scheduler | ||
249 | endif | 250 | endif |
250 | 251 | ||
251 | if HAVE_SSH_KEY | 252 | if HAVE_SSH_KEY |
@@ -608,6 +609,11 @@ perf_malloc_SOURCES = \ | |||
608 | perf_malloc_LDADD = \ | 609 | perf_malloc_LDADD = \ |
609 | libgnunetutil.la | 610 | libgnunetutil.la |
610 | 611 | ||
612 | perf_scheduler_SOURCES = \ | ||
613 | perf_scheduler.c | ||
614 | perf_scheduler_LDADD = \ | ||
615 | libgnunetutil.la | ||
616 | |||
611 | 617 | ||
612 | EXTRA_DIST = \ | 618 | EXTRA_DIST = \ |
613 | test_client_data.conf \ | 619 | test_client_data.conf \ |
diff --git a/src/util/perf_scheduler.c b/src/util/perf_scheduler.c new file mode 100644 index 000000000..3ea76e24c --- /dev/null +++ b/src/util/perf_scheduler.c | |||
@@ -0,0 +1,103 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020 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 | * @author Christian Grothoff | ||
22 | * @file util/perf_scheduler.c | ||
23 | * @brief measure performance of scheduler functions | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "gnunet_util_lib.h" | ||
27 | #include <gauger.h> | ||
28 | |||
29 | #define RUNS (1024 * 1024) | ||
30 | |||
31 | static struct GNUNET_SCHEDULER_Task *task; | ||
32 | |||
33 | |||
34 | static void | ||
35 | run (void *cls) | ||
36 | { | ||
37 | uint64_t *count = cls; | ||
38 | |||
39 | task = NULL; | ||
40 | (*count)++; | ||
41 | if (*count >= RUNS) | ||
42 | { | ||
43 | GNUNET_SCHEDULER_shutdown (); | ||
44 | return; | ||
45 | } | ||
46 | task = GNUNET_SCHEDULER_add_now (&run, | ||
47 | count); | ||
48 | } | ||
49 | |||
50 | |||
51 | static void | ||
52 | do_shutdown (void *cls) | ||
53 | { | ||
54 | if (NULL != task) | ||
55 | GNUNET_SCHEDULER_cancel (task); | ||
56 | } | ||
57 | |||
58 | |||
59 | static void | ||
60 | first (void *cls) | ||
61 | { | ||
62 | uint64_t *count = cls; | ||
63 | |||
64 | (*count)++; | ||
65 | task = GNUNET_SCHEDULER_add_now (&run, | ||
66 | count); | ||
67 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | ||
68 | NULL); | ||
69 | } | ||
70 | |||
71 | |||
72 | static uint64_t | ||
73 | perf_scheduler () | ||
74 | { | ||
75 | uint64_t count = 0; | ||
76 | |||
77 | GNUNET_SCHEDULER_run (&first, | ||
78 | &count); | ||
79 | return count; | ||
80 | } | ||
81 | |||
82 | |||
83 | int | ||
84 | main (int argc, char *argv[]) | ||
85 | { | ||
86 | struct GNUNET_TIME_Absolute start; | ||
87 | uint64_t tasks; | ||
88 | |||
89 | start = GNUNET_TIME_absolute_get (); | ||
90 | tasks = perf_scheduler (); | ||
91 | printf ("Scheduler perf took %s\n", | ||
92 | GNUNET_STRINGS_relative_time_to_string ( | ||
93 | GNUNET_TIME_absolute_get_duration (start), | ||
94 | GNUNET_YES)); | ||
95 | GAUGER ("UTIL", "Scheduler", | ||
96 | tasks / 1024 / (1 | ||
97 | + GNUNET_TIME_absolute_get_duration | ||
98 | (start).rel_value_us / 1000LL), "tasks/ms"); | ||
99 | return 0; | ||
100 | } | ||
101 | |||
102 | |||
103 | /* end of perf_scheduler.c */ | ||