-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathparser_bench_test.go
45 lines (39 loc) · 1.27 KB
/
parser_bench_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package httparser
import (
"testing"
)
var benchData = []byte(
"POST /joyent/http-parser HTTP/1.1\r\n" +
"Host: github.com\r\n" +
"DNT: 1\r\n" +
"Accept-Encoding: gzip, deflate, sdch\r\n" +
"Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4\r\n" +
"User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) " +
"AppleWebKit/537.36 (KHTML, like Gecko) " +
"Chrome/39.0.2171.65 Safari/537.36\r\n" +
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9," +
"image/webp,*/*;q=0.8\r\n" +
"Referer: https://github.com/joyent/http-parser\r\n" +
"Connection: keep-alive\r\n" +
"Transfer-Encoding: chunked\r\n" +
"Cache-Control: max-age=0\r\n\r\nb\r\nhello world\r\n0\r\n")
var setting = Setting{
MessageBegin: func(*Parser, int) {},
URL: func(*Parser, []byte, int) {},
Status: func(*Parser, []byte, int) {},
HeaderField: func(*Parser, []byte, int) {},
HeaderValue: func(*Parser, []byte, int) {},
HeadersComplete: func(*Parser, int) {},
Body: func(*Parser, []byte, int) {},
MessageComplete: func(*Parser, int) {},
}
func Benchmark_Parser(b *testing.B) {
p := New(REQUEST)
for i := 0; i < b.N; i++ {
_, err := p.Execute(&setting, benchData)
if err != nil {
panic(err.Error())
}
p.Reset()
}
}