3 个不稳定版本
使用旧的 Rust 2015
0.2.0 | 2018年12月22日 |
---|---|
0.1.1 | 2018年5月19日 |
0.1.0 | 2018年5月19日 |
#3 in #buf-mut
41KB
1K SLoC
非常快速的 HTTP 解析器 - Totemo-Hayai (とても速い) HTTP 解析器
用法
let buf = b"GET / HTTP/1.1\r\nHost: example.com";
let mut headers = Vec::<thhp::HeaderField>::with_capacity(16);
match thhp::Request::parse(buf, &mut headers) {
Ok(thhp::Complete((ref req, len))) => {
// Use request.
},
Ok(thhp::Incomplete) => {
// Read more and parse again.
},
Err(err) => {
// Handle error.
}
}
基准测试
显式使用 SSE4.2
$ RUSTFLAGS="-C target-feature=+sse4.2" cargo +nightly bench
...
test bench_httparse ... bench: 279 ns/iter (+/- 18) = 2519 MB/s
test bench_httparse_short ... bench: 41 ns/iter (+/- 9) = 1365 MB/s
test bench_picohttpparser ... bench: 160 ns/iter (+/- 37) = 4393 MB/s
test bench_picohttpparser_short ... bench: 45 ns/iter (+/- 5) = 1244 MB/s
test bench_thhp ... bench: 159 ns/iter (+/- 23) = 4421 MB/s
test bench_thhp_short ... bench: 35 ns/iter (+/- 5) = 1600 MB/s
...
隐式使用 SSE4.2
$ cargo +nightly bench
...
test bench_httparse ... bench: 208 ns/iter (+/- 26) = 3379 MB/s
test bench_httparse_short ... bench: 41 ns/iter (+/- 4) = 1365 MB/s
test bench_picohttpparser ... bench: 153 ns/iter (+/- 24) = 4594 MB/s
test bench_picohttpparser_short ... bench: 42 ns/iter (+/- 7) = 1333 MB/s
test bench_thhp ... bench: 198 ns/iter (+/- 33) = 3550 MB/s
test bench_thhp_short ... bench: 37 ns/iter (+/- 8) = 1513 MB/s
...
依赖关系
~24KB