github.com/moontrade/nogc@v0.1.7/net/http/bench.cd (about)

     1  /*
     2   * Copyright (c) 2009-2014 Kazuho Oku, Tokuhiro Matsuno, Daisuke Murase,
     3   *                         Shigeo Mitsunari
     4   *
     5   * The software is licensed under either the MIT License (below) or the Perl
     6   * license.
     7   *
     8   * Permission is hereby granted, free of charge, to any person obtaining a copy
     9   * of this software and associated documentation files (the "Software"), to
    10   * deal in the Software without restriction, including without limitation the
    11   * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
    12   * sell copies of the Software, and to permit persons to whom the Software is
    13   * furnished to do so, subject to the following conditions:
    14   *
    15   * The above copyright notice and this permission notice shall be included in
    16   * all copies or substantial portions of the Software.
    17   *
    18   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    19   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    20   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    21   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    22   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    23   * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
    24   * IN THE SOFTWARE.
    25   */
    26  
    27  #include <assert.h>
    28  #include <stdio.h>
    29  #include "picohttpparser.h"
    30  
    31  #define REQ                                                                                                                        \
    32      "GET /wp-content/uploads/2010/03/hello-kitty-darth-vader-pink.jpg HTTP/1.1\r\n"                                                \
    33      "Host: www.kittyhell.com\r\n"                                                                                                  \
    34      "User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; ja-JP-mac; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 "             \
    35      "Pathtraq/0.9\r\n"                                                                                                             \
    36      "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"                                                  \
    37      "Accept-Language: ja,en-us;q=0.7,en;q=0.3\r\n"                                                                                 \
    38      "Accept-Encoding: gzip,deflate\r\n"                                                                                            \
    39      "Accept-Charset: Shift_JIS,utf-8;q=0.7,*;q=0.7\r\n"                                                                            \
    40      "Keep-Alive: 115\r\n"                                                                                                          \
    41      "Connection: keep-alive\r\n"                                                                                                   \
    42      "Cookie: wp_ozh_wsa_visits=2; wp_ozh_wsa_visit_lasttime=xxxxxxxxxx; "                                                          \
    43      "__utma=xxxxxxxxx.xxxxxxxxxx.xxxxxxxxxx.xxxxxxxxxx.xxxxxxxxxx.x; "                                                             \
    44      "__utmz=xxxxxxxxx.xxxxxxxxxx.x.x.utmccn=(referral)|utmcsr=reader.livedoor.com|utmcct=/reader/|utmcmd=referral\r\n"             \
    45      "\r\n"
    46  
    47  int main(void)
    48  {
    49      const char *method;
    50      size_t method_len;
    51      const char *path;
    52      size_t path_len;
    53      int minor_version;
    54      struct phr_header headers[32];
    55      size_t num_headers;
    56      int i, ret;
    57  
    58      for (i = 0; i < 10000000; i++) {
    59          num_headers = sizeof(headers) / sizeof(headers[0]);
    60          ret = phr_parse_request(REQ, sizeof(REQ) - 1, &method, &method_len, &path, &path_len, &minor_version, headers, &num_headers,
    61                                  0);
    62          assert(ret == sizeof(REQ) - 1);
    63      }
    64  
    65      return 0;
    66  }