diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-10-12 09:25:52 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-10-12 09:25:52 +0000 |
commit | a7fd3c7f54ff564022b95cb0523a5a6f19fc00c5 (patch) | |
tree | 5ec8966633815d08a1cce1902a26cd663073ebc2 | |
parent | 932f1bfbbdff192e00f018cb7bface3fb2d1c27a (diff) | |
download | libmicrohttpd-a7fd3c7f54ff564022b95cb0523a5a6f19fc00c5.tar.gz libmicrohttpd-a7fd3c7f54ff564022b95cb0523a5a6f19fc00c5.zip |
speed up test case, print performance
-rw-r--r-- | src/testcurl/daemontest_post_loop.c | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/src/testcurl/daemontest_post_loop.c b/src/testcurl/daemontest_post_loop.c index 6a007490..0fe52e78 100644 --- a/src/testcurl/daemontest_post_loop.c +++ b/src/testcurl/daemontest_post_loop.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <stdlib.h> | 31 | #include <stdlib.h> |
32 | #include <string.h> | 32 | #include <string.h> |
33 | #include <time.h> | 33 | #include <time.h> |
34 | #include <gauger.h> | ||
34 | 35 | ||
35 | #ifndef WINDOWS | 36 | #ifndef WINDOWS |
36 | #include <unistd.h> | 37 | #include <unistd.h> |
@@ -38,7 +39,7 @@ | |||
38 | 39 | ||
39 | #define POST_DATA "<?xml version='1.0' ?>\n<xml>\n<data-id>1</data-id>\n</xml>\n" | 40 | #define POST_DATA "<?xml version='1.0' ?>\n<xml>\n<data-id>1</data-id>\n</xml>\n" |
40 | 41 | ||
41 | #define LOOPCOUNT 10 | 42 | #define LOOPCOUNT 1000 |
42 | 43 | ||
43 | static int oneone; | 44 | static int oneone; |
44 | 45 | ||
@@ -329,7 +330,8 @@ testExternalPost () | |||
329 | } | 330 | } |
330 | for (i = 0; i < LOOPCOUNT; i++) | 331 | for (i = 0; i < LOOPCOUNT; i++) |
331 | { | 332 | { |
332 | fprintf (stderr, "."); | 333 | if (99 == i % 100) |
334 | fprintf (stderr, "."); | ||
333 | c = curl_easy_init (); | 335 | c = curl_easy_init (); |
334 | cbc.pos = 0; | 336 | cbc.pos = 0; |
335 | buf[0] = '\0'; | 337 | buf[0] = '\0'; |
@@ -390,6 +392,8 @@ testExternalPost () | |||
390 | if ((CURLM_OK == curl_multi_timeout (multi, &ctimeout)) && | 392 | if ((CURLM_OK == curl_multi_timeout (multi, &ctimeout)) && |
391 | (ctimeout < timeout) && (ctimeout >= 0)) | 393 | (ctimeout < timeout) && (ctimeout >= 0)) |
392 | timeout = ctimeout; | 394 | timeout = ctimeout; |
395 | if (c == NULL) | ||
396 | timeout = 0; /* terminate quickly... */ | ||
393 | tv.tv_sec = timeout / 1000; | 397 | tv.tv_sec = timeout / 1000; |
394 | tv.tv_usec = (timeout % 1000) * 1000; | 398 | tv.tv_usec = (timeout % 1000) * 1000; |
395 | select (max + 1, &rs, &ws, &es, &tv); | 399 | select (max + 1, &rs, &ws, &es, &tv); |
@@ -433,6 +437,27 @@ testExternalPost () | |||
433 | } | 437 | } |
434 | 438 | ||
435 | 439 | ||
440 | /** | ||
441 | * Time this round was started. | ||
442 | */ | ||
443 | static unsigned long long start_time; | ||
444 | |||
445 | |||
446 | /** | ||
447 | * Get the current timestamp | ||
448 | * | ||
449 | * @return current time in ms | ||
450 | */ | ||
451 | static unsigned long long | ||
452 | now () | ||
453 | { | ||
454 | struct timeval tv; | ||
455 | |||
456 | GETTIMEOFDAY (&tv, NULL); | ||
457 | return (((unsigned long long) tv.tv_sec * 1000LL) + | ||
458 | ((unsigned long long) tv.tv_usec / 1000LL)); | ||
459 | } | ||
460 | |||
436 | 461 | ||
437 | int | 462 | int |
438 | main (int argc, char *const *argv) | 463 | main (int argc, char *const *argv) |
@@ -442,10 +467,46 @@ main (int argc, char *const *argv) | |||
442 | oneone = NULL != strstr (argv[0], "11"); | 467 | oneone = NULL != strstr (argv[0], "11"); |
443 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 468 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) |
444 | return 2; | 469 | return 2; |
470 | start_time = now(); | ||
445 | errorCount += testInternalPost (); | 471 | errorCount += testInternalPost (); |
472 | fprintf (stderr, | ||
473 | oneone ? "%s: Sequential POSTs (http/1.1) %f/s" : "%s: Sequential POSTs (http/1.0) %f/s", | ||
474 | "internal select", | ||
475 | (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0)); | ||
476 | GAUGER ("internal select", | ||
477 | oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)", | ||
478 | (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0), | ||
479 | "requests/s"); | ||
480 | start_time = now(); | ||
446 | errorCount += testMultithreadedPost (); | 481 | errorCount += testMultithreadedPost (); |
482 | fprintf (stderr, | ||
483 | oneone ? "%s: Sequential POSTs (http/1.1) %f/s" : "%s: Sequential POSTs (http/1.0) %f/s", | ||
484 | "multithreaded post", | ||
485 | (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0)); | ||
486 | GAUGER ("Multithreaded select", | ||
487 | oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)", | ||
488 | (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0), | ||
489 | "requests/s"); | ||
490 | start_time = now(); | ||
447 | errorCount += testMultithreadedPoolPost (); | 491 | errorCount += testMultithreadedPoolPost (); |
492 | fprintf (stderr, | ||
493 | oneone ? "%s: Sequential POSTs (http/1.1) %f/s" : "%s: Sequential POSTs (http/1.0) %f/s", | ||
494 | "thread with pool", | ||
495 | (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0)); | ||
496 | GAUGER ("thread with pool", | ||
497 | oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)", | ||
498 | (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0), | ||
499 | "requests/s"); | ||
500 | start_time = now(); | ||
448 | errorCount += testExternalPost (); | 501 | errorCount += testExternalPost (); |
502 | fprintf (stderr, | ||
503 | oneone ? "%s: Sequential POSTs (http/1.1) %f/s" : "%s: Sequential POSTs (http/1.0) %f/s", | ||
504 | "external select", | ||
505 | (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0)); | ||
506 | GAUGER ("external select", | ||
507 | oneone ? "Sequential POSTs (http/1.1)" : "Sequential POSTs (http/1.0)", | ||
508 | (double) 1000 * LOOPCOUNT / (now() - start_time + 1.0), | ||
509 | "requests/s"); | ||
449 | if (errorCount != 0) | 510 | if (errorCount != 0) |
450 | fprintf (stderr, "Error (code: %u)\n", errorCount); | 511 | fprintf (stderr, "Error (code: %u)\n", errorCount); |
451 | curl_global_cleanup (); | 512 | curl_global_cleanup (); |