-
Notifications
You must be signed in to change notification settings - Fork 351
Expand file tree
/
Copy pathhttpparsebench.cpp
More file actions
64 lines (54 loc) · 1.72 KB
/
httpparsebench.cpp
File metadata and controls
64 lines (54 loc) · 1.72 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "icy/http/parser.h"
#include "icy/http/request.h"
#include "icy/http/response.h"
#include "benchutil.h"
#include <cstdint>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace icy;
namespace {
void benchParse(bench::Reporter& reporter)
{
static const std::string requestWire =
"POST /api/v1/items?limit=10 HTTP/1.1\r\n"
"Host: 127.0.0.1:8080\r\n"
"User-Agent: icey-bench\r\n"
"Accept: application/json\r\n"
"Content-Type: application/json\r\n"
"Content-Length: 26\r\n"
"Connection: keep-alive\r\n"
"\r\n"
"{\"name\":\"icey\",\"count\":42}";
constexpr uint64_t iterations = 100000;
uint64_t bytes = 0;
uint64_t checksum = 0;
const auto measurement = bench::measure(reporter.options(), iterations, [&] {
bytes = 0;
checksum = 0;
for (uint64_t index = 0; index < iterations; ++index) {
http::Request request;
http::Parser parser(&request);
auto result = parser.parse(requestWire.data(), requestWire.size());
if (!result.ok() || !result.messageComplete) {
std::cerr << "httpparsebench: parse failed\n";
std::exit(1);
}
bytes += result.bytesConsumed;
checksum += request.getMethod().size() + request.size();
}
});
reporter.add({
.name = "http request parse",
.measurement = measurement,
.metrics = {bench::metric("bytes", bytes / iterations),
bench::metric("checksum", checksum)},
});
}
} // namespace
int main(int argc, char** argv)
{
bench::Reporter reporter(argc, argv);
benchParse(reporter);
return reporter.finish();
}