aboutsummaryrefslogtreecommitdiff
path: root/src/util/test_speedup.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-05-31 18:51:04 +0000
committerChristian Grothoff <christian@grothoff.org>2012-05-31 18:51:04 +0000
commitcc983a47bc9a0d6a32f37b494b65bbb79c16c0c6 (patch)
treee50e41f3d2fc33e9ecfbaa639fd7ec98491d8949 /src/util/test_speedup.c
parent7de9f07b0fc3729679ad2678ce1a04aed88e0f7f (diff)
downloadgnunet-cc983a47bc9a0d6a32f37b494b65bbb79c16c0c6.tar.gz
gnunet-cc983a47bc9a0d6a32f37b494b65bbb79c16c0c6.zip
-fixing speedup test
Diffstat (limited to 'src/util/test_speedup.c')
-rw-r--r--src/util/test_speedup.c92
1 files changed, 53 insertions, 39 deletions
diff --git a/src/util/test_speedup.c b/src/util/test_speedup.c
index 47603d35c..03cffbd54 100644
--- a/src/util/test_speedup.c
+++ b/src/util/test_speedup.c
@@ -27,36 +27,54 @@
27#include "gnunet_time_lib.h" 27#include "gnunet_time_lib.h"
28#include "gnunet_strings_lib.h" 28#include "gnunet_strings_lib.h"
29 29
30 30/**
31#define VERBOSE GNUNET_NO 31 * Start time of the testcase
32 32 */
33static struct GNUNET_TIME_Absolute start; 33static struct GNUNET_TIME_Absolute start;
34
35/**
36 * End-time of the testcase (affected by speed-up)
37 */
34static struct GNUNET_TIME_Absolute end; 38static struct GNUNET_TIME_Absolute end;
35static int cycles;
36 39
40/**
41 * Number of cycles we have spent in 'run'.
42 */
43static unsigned int cycles;
44
45
46/**
47 * Main task that is scheduled with the speed-up.
48 *
49 * @param cls NULL
50 * @param tc scheduler context, unused
51 */
37static void 52static void
38run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 53run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
39{ 54{
40 55 cycles++;
41 cycles ++; 56 fprintf (stderr, "..%u", cycles);
42 printf ("..%u", cycles);
43 fflush(stdout);
44 if (cycles <= 5) 57 if (cycles <= 5)
45 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &run, NULL);
46 else
47 { 58 {
48 end = GNUNET_TIME_absolute_get(); 59 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &run, NULL);
49 printf ("\n"); 60 return;
50 fflush(stdout);
51 } 61 }
62 end = GNUNET_TIME_absolute_get();
63 fprintf (stderr, "\n");
64 fflush(stdout);
52} 65}
53 66
54void check (void *cls, char *const *args, 67
55 const char *cfgfile, 68/**
56 const struct GNUNET_CONFIGURATION_Handle * 69 *
57 cfg) 70 */
71static void
72check (void *cls, char *const *args,
73 const char *cfgfile,
74 const struct GNUNET_CONFIGURATION_Handle *
75 cfg)
58{ 76{
59 printf ("0"); 77 fprintf (stderr, "0");
60 fflush(stdout); 78 fflush(stdout);
61 GNUNET_SCHEDULER_add_now(&run, NULL); 79 GNUNET_SCHEDULER_add_now(&run, NULL);
62} 80}
@@ -65,42 +83,38 @@ void check (void *cls, char *const *args,
65int 83int
66main (int argc, char *argv[]) 84main (int argc, char *argv[])
67{ 85{
68 time_t start_real;
69 time_t end_real;
70 struct GNUNET_TIME_Relative delta;
71
72 static char *const argvn[] = { "test-speedup", 86 static char *const argvn[] = { "test-speedup",
73 "-c", 87 "-c", "test_speedup_data.conf",
74 "test_speedup_data.conf",
75#if VERBOSE
76 "-L", "DEBUG",
77#endif
78 NULL 88 NULL
79 }; 89 };
80 start_real = time (NULL);
81 start = GNUNET_TIME_absolute_get();
82 static struct GNUNET_GETOPT_CommandLineOption options[] = { 90 static struct GNUNET_GETOPT_CommandLineOption options[] = {
83 GNUNET_GETOPT_OPTION_END 91 GNUNET_GETOPT_OPTION_END
84 }; 92 };
85 93 time_t start_real;
94 time_t end_real;
95 struct GNUNET_TIME_Relative delta;
96
97 start_real = time (NULL);
98 start = GNUNET_TIME_absolute_get();
86 GNUNET_PROGRAM_run ((sizeof (argvn) / sizeof (char *)) - 1, argvn, "test-speedup", 99 GNUNET_PROGRAM_run ((sizeof (argvn) / sizeof (char *)) - 1, argvn, "test-speedup",
87 "nohelp", options, &check, NULL); 100 "nohelp", options, &check, NULL);
88 101
89 end_real = time (NULL); 102 end_real = time (NULL);
90 delta = GNUNET_TIME_absolute_get_difference(start, end); 103 delta = GNUNET_TIME_absolute_get_difference(start, end);
91 104
92 if (delta.rel_value > ((end_real - start_real) * 1500)) 105 if (delta.rel_value > ((end_real - start_real) * 1500LL))
93 { 106 {
94 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Execution time in GNUnet time: %llu ms\n", delta.rel_value); 107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Execution time in GNUnet time: %llu ms\n",
95 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Execution time in system time: %llu ms\n", (end_real - start_real) * 1000); 108 (unsigned long long) delta.rel_value);
109 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Execution time in system time: %llu ms\n",
110 (unsigned long long) ((end_real - start_real) * 1000LL));
96 return 0; 111 return 0;
97 } 112 }
98 else 113 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Execution time in GNUnet time: %llu ms\n",
99 { 114 (unsigned long long) delta.rel_value);
100 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Execution time in GNUnet time: %llu ms\n", delta.rel_value); 115 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Execution time in system time: %llu ms\n",
101 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Execution time in system time: %llu ms\n", (end_real - start_real) * 1000); 116 (unsigned long long) ((end_real - start_real) * 1000LL));
102 return 1; 117 return 1;
103 }
104} 118}
105 119
106/* end of test_speedup.c */ 120/* end of test_speedup.c */