![](/media/cache/profiles/1006ff12c465532f8c574aeaa4461b16.50x50_q85.jpg)
Performance problems with HTTPText. This is a test program for the problems.
Dependencies: EthernetNetIf mbed
main.cpp@1:20a89656f772, 2010-10-09 (annotated)
- Committer:
- shintamainjp
- Date:
- Sat Oct 09 22:51:52 2010 +0000
- Revision:
- 1:20a89656f772
- Parent:
- 0:fd0a4a9e317c
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shintamainjp | 0:fd0a4a9e317c | 1 | /** |
shintamainjp | 0:fd0a4a9e317c | 2 | * Performance problems with HTTPText. |
shintamainjp | 1:20a89656f772 | 3 | * |
shintamainjp | 0:fd0a4a9e317c | 4 | * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems) |
shintamainjp | 0:fd0a4a9e317c | 5 | * http://shinta.main.jp/ |
shintamainjp | 0:fd0a4a9e317c | 6 | */ |
shintamainjp | 0:fd0a4a9e317c | 7 | |
shintamainjp | 0:fd0a4a9e317c | 8 | #include "mbed.h" |
shintamainjp | 0:fd0a4a9e317c | 9 | #include "EthernetNetIf.h" |
shintamainjp | 0:fd0a4a9e317c | 10 | #include "HTTPClient.h" |
shintamainjp | 0:fd0a4a9e317c | 11 | |
shintamainjp | 1:20a89656f772 | 12 | static const int ClientTimeoutMs = 1000; |
shintamainjp | 1:20a89656f772 | 13 | |
shintamainjp | 0:fd0a4a9e317c | 14 | EthernetNetIf netif; |
shintamainjp | 0:fd0a4a9e317c | 15 | Timer timer; |
shintamainjp | 0:fd0a4a9e317c | 16 | |
shintamainjp | 0:fd0a4a9e317c | 17 | void test(int bufsiz); |
shintamainjp | 0:fd0a4a9e317c | 18 | int main(void); |
shintamainjp | 0:fd0a4a9e317c | 19 | |
shintamainjp | 0:fd0a4a9e317c | 20 | /** |
shintamainjp | 0:fd0a4a9e317c | 21 | * Execute the test. |
shintamainjp | 0:fd0a4a9e317c | 22 | * |
shintamainjp | 0:fd0a4a9e317c | 23 | * @param bufsiz Buffer size of a HTTPText. |
shintamainjp | 0:fd0a4a9e317c | 24 | */ |
shintamainjp | 0:fd0a4a9e317c | 25 | void test(int bufsiz) { |
shintamainjp | 0:fd0a4a9e317c | 26 | HTTPClient client; |
shintamainjp | 0:fd0a4a9e317c | 27 | HTTPMap map; |
shintamainjp | 0:fd0a4a9e317c | 28 | HTTPText text("text/html", bufsiz); |
shintamainjp | 1:20a89656f772 | 29 | |
shintamainjp | 1:20a89656f772 | 30 | client.setTimeout(ClientTimeoutMs); |
shintamainjp | 1:20a89656f772 | 31 | |
shintamainjp | 0:fd0a4a9e317c | 32 | int sizelist[10] = { |
shintamainjp | 0:fd0a4a9e317c | 33 | 8, |
shintamainjp | 0:fd0a4a9e317c | 34 | 16, |
shintamainjp | 0:fd0a4a9e317c | 35 | 32, |
shintamainjp | 0:fd0a4a9e317c | 36 | 64, |
shintamainjp | 0:fd0a4a9e317c | 37 | 128, |
shintamainjp | 0:fd0a4a9e317c | 38 | 256, |
shintamainjp | 0:fd0a4a9e317c | 39 | 512, |
shintamainjp | 0:fd0a4a9e317c | 40 | 1024, |
shintamainjp | 0:fd0a4a9e317c | 41 | 2048, |
shintamainjp | 0:fd0a4a9e317c | 42 | 4096 |
shintamainjp | 0:fd0a4a9e317c | 43 | }; |
shintamainjp | 0:fd0a4a9e317c | 44 | |
shintamainjp | 1:20a89656f772 | 45 | printf("(Buffer size of a HTTPText : %d)\n", bufsiz); |
shintamainjp | 1:20a89656f772 | 46 | printf("+---------+--------+------+--------+\n"); |
shintamainjp | 1:20a89656f772 | 47 | printf("|File size|Time[ms]|Result|Response|\n"); |
shintamainjp | 1:20a89656f772 | 48 | printf("+---------+--------+------+--------+\n"); |
shintamainjp | 0:fd0a4a9e317c | 49 | for (int i = 0; i < sizeof(sizelist) / sizeof(sizelist[0]); i++) { |
shintamainjp | 0:fd0a4a9e317c | 50 | char url[256]; |
shintamainjp | 0:fd0a4a9e317c | 51 | sprintf(url, "http://mbed.org/media/uploads/shintamainjp/textfile_%dbytes.txt", sizelist[i]); |
shintamainjp | 0:fd0a4a9e317c | 52 | timer.stop(); |
shintamainjp | 0:fd0a4a9e317c | 53 | timer.reset(); |
shintamainjp | 0:fd0a4a9e317c | 54 | timer.start(); |
shintamainjp | 0:fd0a4a9e317c | 55 | HTTPResult r = client.get(url, &text); |
shintamainjp | 0:fd0a4a9e317c | 56 | timer.stop(); |
shintamainjp | 1:20a89656f772 | 57 | printf("|%9d|%8d|%6d|%8d|\n", sizelist[i], timer.read_ms(), (int)r, client.getHTTPResponseCode()); |
shintamainjp | 0:fd0a4a9e317c | 58 | } |
shintamainjp | 1:20a89656f772 | 59 | printf("+---------+--------+------+--------+\n"); |
shintamainjp | 0:fd0a4a9e317c | 60 | } |
shintamainjp | 0:fd0a4a9e317c | 61 | |
shintamainjp | 0:fd0a4a9e317c | 62 | /** |
shintamainjp | 0:fd0a4a9e317c | 63 | * Entry point. |
shintamainjp | 0:fd0a4a9e317c | 64 | */ |
shintamainjp | 0:fd0a4a9e317c | 65 | int main(void) { |
shintamainjp | 0:fd0a4a9e317c | 66 | int bufsizlist[10] = { |
shintamainjp | 0:fd0a4a9e317c | 67 | 8, |
shintamainjp | 0:fd0a4a9e317c | 68 | 16, |
shintamainjp | 0:fd0a4a9e317c | 69 | 32, |
shintamainjp | 0:fd0a4a9e317c | 70 | 64, |
shintamainjp | 0:fd0a4a9e317c | 71 | 128, |
shintamainjp | 0:fd0a4a9e317c | 72 | 256, |
shintamainjp | 0:fd0a4a9e317c | 73 | 512, |
shintamainjp | 0:fd0a4a9e317c | 74 | 1024, |
shintamainjp | 0:fd0a4a9e317c | 75 | 2048, |
shintamainjp | 0:fd0a4a9e317c | 76 | 4096 |
shintamainjp | 0:fd0a4a9e317c | 77 | }; |
shintamainjp | 0:fd0a4a9e317c | 78 | |
shintamainjp | 0:fd0a4a9e317c | 79 | EthernetErr ethErr = netif.setup(); |
shintamainjp | 0:fd0a4a9e317c | 80 | if (ethErr) { |
shintamainjp | 0:fd0a4a9e317c | 81 | error("Network setup failed.\n"); |
shintamainjp | 0:fd0a4a9e317c | 82 | } |
shintamainjp | 0:fd0a4a9e317c | 83 | |
shintamainjp | 0:fd0a4a9e317c | 84 | for (int i = 0; i < sizeof(bufsizlist) / sizeof(bufsizlist[0]); i++) { |
shintamainjp | 0:fd0a4a9e317c | 85 | printf("\n"); |
shintamainjp | 0:fd0a4a9e317c | 86 | test(bufsizlist[i]); |
shintamainjp | 0:fd0a4a9e317c | 87 | } |
shintamainjp | 0:fd0a4a9e317c | 88 | } |