diff options
Diffstat (limited to 'src/examples/benchmark.c')
-rw-r--r-- | src/examples/benchmark.c | 79 |
1 files changed, 41 insertions, 38 deletions
diff --git a/src/examples/benchmark.c b/src/examples/benchmark.c index 9512b9bf..2a8fb179 100644 --- a/src/examples/benchmark.c +++ b/src/examples/benchmark.c | |||
@@ -25,14 +25,15 @@ | |||
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | #include <microhttpd.h> | 26 | #include <microhttpd.h> |
27 | 27 | ||
28 | #if defined(CPU_COUNT) && (CPU_COUNT+0) < 2 | 28 | #if defined(CPU_COUNT) && (CPU_COUNT + 0) < 2 |
29 | #undef CPU_COUNT | 29 | #undef CPU_COUNT |
30 | #endif | 30 | #endif |
31 | #if !defined(CPU_COUNT) | 31 | #if ! defined(CPU_COUNT) |
32 | #define CPU_COUNT 2 | 32 | #define CPU_COUNT 2 |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | #define PAGE "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>" | 35 | #define PAGE \ |
36 | "<html><head><title>libmicrohttpd demo</title></head><body>libmicrohttpd demo</body></html>" | ||
36 | 37 | ||
37 | 38 | ||
38 | #define SMALL (1024 * 128) | 39 | #define SMALL (1024 * 128) |
@@ -62,16 +63,16 @@ static struct MHD_Response *response; | |||
62 | */ | 63 | */ |
63 | static void | 64 | static void |
64 | completed_callback (void *cls, | 65 | completed_callback (void *cls, |
65 | struct MHD_Connection *connection, | 66 | struct MHD_Connection *connection, |
66 | void **con_cls, | 67 | void **con_cls, |
67 | enum MHD_RequestTerminationCode toe) | 68 | enum MHD_RequestTerminationCode toe) |
68 | { | 69 | { |
69 | struct timeval *tv = *con_cls; | 70 | struct timeval *tv = *con_cls; |
70 | struct timeval tve; | 71 | struct timeval tve; |
71 | uint64_t delta; | 72 | uint64_t delta; |
72 | (void)cls; /* Unused. Silent compiler warning. */ | 73 | (void) cls; /* Unused. Silent compiler warning. */ |
73 | (void)connection; /* Unused. Silent compiler warning. */ | 74 | (void) connection; /* Unused. Silent compiler warning. */ |
74 | (void)toe; /* Unused. Silent compiler warning. */ | 75 | (void) toe; /* Unused. Silent compiler warning. */ |
75 | 76 | ||
76 | if (NULL == tv) | 77 | if (NULL == tv) |
77 | return; | 78 | return; |
@@ -80,10 +81,10 @@ completed_callback (void *cls, | |||
80 | delta = 0; | 81 | delta = 0; |
81 | if (tve.tv_usec >= tv->tv_usec) | 82 | if (tve.tv_usec >= tv->tv_usec) |
82 | delta += (tve.tv_sec - tv->tv_sec) * 1000000LL | 83 | delta += (tve.tv_sec - tv->tv_sec) * 1000000LL |
83 | + (tve.tv_usec - tv->tv_usec); | 84 | + (tve.tv_usec - tv->tv_usec); |
84 | else | 85 | else |
85 | delta += (tve.tv_sec - tv->tv_sec) * 1000000LL | 86 | delta += (tve.tv_sec - tv->tv_sec) * 1000000LL |
86 | - tv->tv_usec + tve.tv_usec; | 87 | - tv->tv_usec + tve.tv_usec; |
87 | if (delta < SMALL) | 88 | if (delta < SMALL) |
88 | small_deltas[delta]++; | 89 | small_deltas[delta]++; |
89 | else | 90 | else |
@@ -94,11 +95,11 @@ completed_callback (void *cls, | |||
94 | 95 | ||
95 | static void * | 96 | static void * |
96 | uri_logger_cb (void *cls, | 97 | uri_logger_cb (void *cls, |
97 | const char *uri) | 98 | const char *uri) |
98 | { | 99 | { |
99 | struct timeval *tv = malloc (sizeof (struct timeval)); | 100 | struct timeval *tv = malloc (sizeof (struct timeval)); |
100 | (void)cls; /* Unused. Silent compiler warning. */ | 101 | (void) cls; /* Unused. Silent compiler warning. */ |
101 | (void)uri; /* Unused. Silent compiler warning. */ | 102 | (void) uri; /* Unused. Silent compiler warning. */ |
102 | 103 | ||
103 | if (NULL != tv) | 104 | if (NULL != tv) |
104 | gettimeofday (tv, NULL); | 105 | gettimeofday (tv, NULL); |
@@ -114,12 +115,12 @@ ahc_echo (void *cls, | |||
114 | const char *version, | 115 | const char *version, |
115 | const char *upload_data, size_t *upload_data_size, void **ptr) | 116 | const char *upload_data, size_t *upload_data_size, void **ptr) |
116 | { | 117 | { |
117 | (void)cls; /* Unused. Silent compiler warning. */ | 118 | (void) cls; /* Unused. Silent compiler warning. */ |
118 | (void)url; /* Unused. Silent compiler warning. */ | 119 | (void) url; /* Unused. Silent compiler warning. */ |
119 | (void)version; /* Unused. Silent compiler warning. */ | 120 | (void) version; /* Unused. Silent compiler warning. */ |
120 | (void)upload_data; /* Unused. Silent compiler warning. */ | 121 | (void) upload_data; /* Unused. Silent compiler warning. */ |
121 | (void)upload_data_size; /* Unused. Silent compiler warning. */ | 122 | (void) upload_data_size; /* Unused. Silent compiler warning. */ |
122 | (void)ptr; /* Unused. Silent compiler warning. */ | 123 | (void) ptr; /* Unused. Silent compiler warning. */ |
123 | 124 | ||
124 | if (0 != strcmp (method, "GET")) | 125 | if (0 != strcmp (method, "GET")) |
125 | return MHD_NO; /* unexpected method */ | 126 | return MHD_NO; /* unexpected method */ |
@@ -134,37 +135,39 @@ main (int argc, char *const *argv) | |||
134 | unsigned int i; | 135 | unsigned int i; |
135 | 136 | ||
136 | if (argc != 2) | 137 | if (argc != 2) |
137 | { | 138 | { |
138 | printf ("%s PORT\n", argv[0]); | 139 | printf ("%s PORT\n", argv[0]); |
139 | return 1; | 140 | return 1; |
140 | } | 141 | } |
141 | response = MHD_create_response_from_buffer (strlen (PAGE), | 142 | response = MHD_create_response_from_buffer (strlen (PAGE), |
142 | (void *) PAGE, | 143 | (void *) PAGE, |
143 | MHD_RESPMEM_PERSISTENT); | 144 | MHD_RESPMEM_PERSISTENT); |
144 | #if 0 | 145 | #if 0 |
145 | (void) MHD_add_response_header (response, | 146 | (void) MHD_add_response_header (response, |
146 | MHD_HTTP_HEADER_CONNECTION, | 147 | MHD_HTTP_HEADER_CONNECTION, |
147 | "close"); | 148 | "close"); |
148 | #endif | 149 | #endif |
149 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_SUPPRESS_DATE_NO_CLOCK | 150 | d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD |
151 | | MHD_USE_SUPPRESS_DATE_NO_CLOCK | ||
150 | #ifdef EPOLL_SUPPORT | 152 | #ifdef EPOLL_SUPPORT |
151 | | MHD_USE_EPOLL | MHD_USE_TURBO | 153 | | MHD_USE_EPOLL | MHD_USE_TURBO |
152 | #endif | 154 | #endif |
153 | , | 155 | , |
154 | atoi (argv[1]), | 156 | atoi (argv[1]), |
155 | NULL, NULL, &ahc_echo, NULL, | 157 | NULL, NULL, &ahc_echo, NULL, |
156 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120, | 158 | MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 120, |
157 | MHD_OPTION_THREAD_POOL_SIZE, (unsigned int) NUMBER_OF_THREADS, | 159 | MHD_OPTION_THREAD_POOL_SIZE, (unsigned |
158 | MHD_OPTION_URI_LOG_CALLBACK, &uri_logger_cb, NULL, | 160 | int) NUMBER_OF_THREADS, |
159 | MHD_OPTION_NOTIFY_COMPLETED, &completed_callback, NULL, | 161 | MHD_OPTION_URI_LOG_CALLBACK, &uri_logger_cb, NULL, |
160 | MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 1000, | 162 | MHD_OPTION_NOTIFY_COMPLETED, &completed_callback, NULL, |
161 | MHD_OPTION_END); | 163 | MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 1000, |
164 | MHD_OPTION_END); | ||
162 | if (d == NULL) | 165 | if (d == NULL) |
163 | return 1; | 166 | return 1; |
164 | (void) getc (stdin); | 167 | (void) getc (stdin); |
165 | MHD_stop_daemon (d); | 168 | MHD_stop_daemon (d); |
166 | MHD_destroy_response (response); | 169 | MHD_destroy_response (response); |
167 | for (i=0;i<SMALL;i++) | 170 | for (i = 0; i<SMALL; i++) |
168 | if (0 != small_deltas[i]) | 171 | if (0 != small_deltas[i]) |
169 | fprintf (stdout, "D: %d %u\n", i, small_deltas[i]); | 172 | fprintf (stdout, "D: %d %u\n", i, small_deltas[i]); |
170 | return 0; | 173 | return 0; |