aboutsummaryrefslogtreecommitdiff
path: root/src/lib/util/perf_scheduler.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/util/perf_scheduler.c')
-rw-r--r--src/lib/util/perf_scheduler.c104
1 files changed, 104 insertions, 0 deletions
diff --git a/src/lib/util/perf_scheduler.c b/src/lib/util/perf_scheduler.c
new file mode 100644
index 000000000..af084e04a
--- /dev/null
+++ b/src/lib/util/perf_scheduler.c
@@ -0,0 +1,104 @@
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
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include <gauger.h>
29
30#define RUNS (1024 * 1024)
31
32static struct GNUNET_SCHEDULER_Task *task;
33
34
35static void
36run (void *cls)
37{
38 uint64_t *count = cls;
39
40 task = NULL;
41 (*count)++;
42 if (*count >= RUNS)
43 {
44 GNUNET_SCHEDULER_shutdown ();
45 return;
46 }
47 task = GNUNET_SCHEDULER_add_now (&run,
48 count);
49}
50
51
52static void
53do_shutdown (void *cls)
54{
55 if (NULL != task)
56 GNUNET_SCHEDULER_cancel (task);
57}
58
59
60static void
61first (void *cls)
62{
63 uint64_t *count = cls;
64
65 (*count)++;
66 task = GNUNET_SCHEDULER_add_now (&run,
67 count);
68 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
69 NULL);
70}
71
72
73static uint64_t
74perf_scheduler ()
75{
76 uint64_t count = 0;
77
78 GNUNET_SCHEDULER_run (&first,
79 &count);
80 return count;
81}
82
83
84int
85main (int argc, char *argv[])
86{
87 struct GNUNET_TIME_Absolute start;
88 uint64_t tasks;
89
90 start = GNUNET_TIME_absolute_get ();
91 tasks = perf_scheduler ();
92 printf ("Scheduler perf took %s\n",
93 GNUNET_STRINGS_relative_time_to_string (
94 GNUNET_TIME_absolute_get_duration (start),
95 GNUNET_YES));
96 GAUGER ("UTIL", "Scheduler",
97 tasks / 1024 / (1
98 + GNUNET_TIME_absolute_get_duration
99 (start).rel_value_us / 1000LL), "tasks/ms");
100 return 0;
101}
102
103
104/* end of perf_scheduler.c */