diff --git a/benchmark/http-parser.c b/benchmark/http-parser.c new file mode 100644 index 0000000..8e7c7fd --- /dev/null +++ b/benchmark/http-parser.c @@ -0,0 +1,46 @@ +#include "http_parser.h" +#include +#include +#include +#include +#include + +static http_parser *parser; + +static http_parser_settings settings_null = + {.on_message_begin = 0 + ,.on_header_field = 0 + ,.on_header_value = 0 + ,.on_url = 0 + ,.on_status = 0 + ,.on_body = 0 + ,.on_headers_complete = 0 + ,.on_message_complete = 0 + }; + +int +main (void) +{ + const char *buf; + int i; + float start, end; + size_t parsed; + + parser = malloc(sizeof(http_parser)); + + buf = "GET /cookies HTTP/1.1\r\nHost: 127.0.0.1:8090\r\nConnection: keep-alive\r\nCache-Control: max-age=0\r\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nUser-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.56 Safari/537.17\r\nAccept-Encoding: gzip,deflate,sdch\r\nAccept-Language: en-US,en;q=0.8\r\nAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3\r\nCookie: name=wookie\r\n\r\n"; + + start = (float)clock()/CLOCKS_PER_SEC; + for (i = 0; i < 100000; i++) { + http_parser_init(parser, HTTP_REQUEST); + parsed = http_parser_execute(parser, &settings_null, buf, strlen(buf)); + } + end = (float)clock()/CLOCKS_PER_SEC; + + free(parser); + parser = NULL; + + printf("Elapsed %f seconds.\n", (end - start)); + + return 0; +}