2 This file is part of GNUnet.
3 (C) 2011-2013 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file util/test_speedup.c
22 * @brief testcase for speedup.c
25 #include "gnunet_util_lib.h"
28 * Start time of the testcase
30 static struct GNUNET_TIME_Absolute start;
33 * End-time of the testcase (affected by speed-up)
35 static struct GNUNET_TIME_Absolute end;
38 * Number of cycles we have spent in 'run'.
40 static unsigned int cycles;
44 * Main task that is scheduled with the speed-up.
47 * @param tc scheduler context, unused
50 run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
53 fprintf (stderr, "..%u", cycles);
56 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &run, NULL);
59 end = GNUNET_TIME_absolute_get();
60 fprintf (stderr, "\n");
69 check (void *cls, char *const *args,
71 const struct GNUNET_CONFIGURATION_Handle *
74 fprintf (stderr, "0");
76 GNUNET_SCHEDULER_add_now(&run, NULL);
81 main (int argc, char *argv[])
83 static char *const argvn[] = { "test-speedup",
84 "-c", "test_speedup_data.conf",
87 static struct GNUNET_GETOPT_CommandLineOption options[] = {
88 GNUNET_GETOPT_OPTION_END
92 struct GNUNET_TIME_Relative delta;
94 start_real = time (NULL);
95 start = GNUNET_TIME_absolute_get();
96 GNUNET_PROGRAM_run ((sizeof (argvn) / sizeof (char *)) - 1, argvn, "test-speedup",
97 "nohelp", options, &check, NULL);
99 end_real = time (NULL);
100 delta = GNUNET_TIME_absolute_get_difference (start, end);
102 if (delta.rel_value_us > ((end_real - start_real) * 1500LL * 1000LL))
104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
105 "Execution time in GNUnet time: %s\n",
106 GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_YES));
107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
108 "Execution time in system time: %llu ms\n",
109 (unsigned long long) ((end_real - start_real) * 1000LL));
112 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
113 "Execution time in GNUnet time: %s\n",
114 GNUNET_STRINGS_relative_time_to_string (delta, GNUNET_YES));
115 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
116 "Execution time in system time: %llu ms\n",
117 (unsigned long long) ((end_real - start_real) * 1000LL));
121 /* end of test_speedup.c */