Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a benchmark script for C http-parser.
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#include "http_parser.h" | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <assert.h> | ||
#include <time.h> | ||
|
||
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; | ||
} |