Skip to content

Commit

Permalink
Add a benchmark script for C http-parser.
Browse files Browse the repository at this point in the history
  • Loading branch information
fukamachi committed Apr 7, 2015
1 parent 58d6fa0 commit bd116d8
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions benchmark/http-parser.c
@@ -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;
}

0 comments on commit bd116d8

Please sign in to comment.