26 #include <benchmark/benchmark.h>
88 while (
state.KeepRunning()) {
94 static_cast<size_t>(1024),
103 std::ostringstream
label;
104 label <<
"framing_bytes/iter:"
105 << (
static_cast<double>(
stats.framing_bytes) /
106 static_cast<double>(
state.iterations()))
107 <<
" header_bytes/iter:"
108 << (
static_cast<double>(
stats.header_bytes) /
109 static_cast<double>(
state.iterations()));
115 template <
class Fixture>
119 static bool logged_representative_output =
false;
123 Fixture::Prepare(&
b);
130 while (
state.KeepRunning()) {
131 static constexpr
int kEnsureMaxFrameAtLeast = 2;
136 Fixture::kEnableTrueBinary,
137 static_cast<size_t>(
state.range(1) + kEnsureMaxFrameAtLeast),
141 if (!logged_representative_output &&
state.iterations() > 3) {
142 logged_representative_output =
true;
143 for (
size_t i = 0;
i <
outbuf.count;
i++) {
154 std::ostringstream
label;
155 label <<
"framing_bytes/iter:"
156 << (
static_cast<double>(
stats.framing_bytes) /
157 static_cast<double>(
state.iterations()))
158 <<
" header_bytes/iter:"
159 << (
static_cast<double>(
stats.header_bytes) /
160 static_cast<double>(
state.iterations()));
196 template <
int kLength,
bool kTrueBinary>
208 for (
int i = 0;
i < kLength;
i++) {
209 v.push_back(
static_cast<char>(rand()));
228 "foo.test.google.fr:1234")));
238 "grpc-c/3.0.0-dev (linux; chttp2; green)")));
255 "/grpc.test.FooService/BarMethod")));
258 "foo.test.google.fr:1234")));
261 "\x00\x01\x02\x03\x04\x05\x06\x07\x08"
262 "\x09\x0a\x0b\x0c\x0d\x0e\x0f"
263 "\x10\x11\x12\x13\x14\x15\x16\x17\x18"
264 "\x19\x1a\x1b\x1c\x1d\x1e\x1f"
265 "\x20\x21\x22\x23\x24\x25\x26\x27\x28"
266 "\x29\x2a\x2b\x2c\x2d\x2e\x2f"
270 "\x00\x01\x02\x03\x04\x05\x06\x07\x08"
271 "\x09\x0a\x0b\x0c\x0d\x0e\x0f"
272 "\x10\x11\x12\x13")));
282 "grpc-c/3.0.0-dev (linux; chttp2; green)")));
360 template <
class Fixture>
363 std::vector<grpc_slice> init_slices = Fixture::GetInitSlices();
364 std::vector<grpc_slice> benchmark_slices = Fixture::GetBenchmarkSlices();
367 const int kArenaSize = 4096 * 4096;
376 auto parse_vec = [&
p](
const std::vector<grpc_slice>&
slices) {
377 for (
size_t i = 0;
i <
slices.size(); ++
i) {
382 parse_vec(init_slices);
383 while (
state.KeepRunning()) {
385 parse_vec(benchmark_slices);
388 if (0 == (
state.iterations() & 0xfff)) {
411 template <
class EncoderFixture>
418 static std::vector<grpc_slice>
Generate(
int iteration) {
423 EncoderFixture::Prepare(&
b);
427 std::vector<grpc_slice>
out;
438 EncoderFixture::kEnableTrueBinary,
443 if (
i == iteration) {
444 for (
size_t s = 0; s <
outbuf.count; s++) {
474 {0x40, 0x07,
':',
's',
't',
'a',
't',
'u',
's', 0x03,
'2',
'0',
'0'})};
486 {0x40, 0x07,
':',
's',
't',
'a',
't',
'u',
's', 0x03,
'2',
'0',
'0'})};
494 {0x40, 0x07,
':',
's',
't',
'a',
't',
'u',
's', 0x03,
'2',
'0',
'0'})};
497 return {
MakeSlice({0x7e, 0x03,
'4',
'0',
'4'})};
504 return {
MakeSlice({0x40, 0x03,
'a',
'b',
'c', 0x03,
'd',
'e',
'f'})};
515 return {
MakeSlice({0x40, 0x03,
'a',
'b',
'c', 0x03,
'd',
'e',
'f'})};
522 return {
MakeSlice({0x40, 0x03,
'a',
'b',
'c', 0x03,
'd',
'e',
'f'})};
525 return {
MakeSlice({0x7e, 0x03,
'g',
'h',
'i'})};
533 return {
MakeSlice({0x00, 0x03,
'a',
'b',
'c', 0x03,
'd',
'e',
'f'})};
537 template <
int kLength,
bool kTrueBinary>
540 template <
int kLength>
545 std::vector<uint8_t>
v = {
546 0x00, 0x07,
'a',
'b',
'c',
547 '-',
'b',
'i',
'n',
static_cast<uint8_t>(kLength + 1),
549 for (
int i = 0;
i < kLength;
i++) {
562 {0x00, 0x07,
'a',
'b',
'c',
'-',
'b',
'i',
'n', 0x82, 0xf7, 0xb3})};
571 return {
MakeSlice({0x00, 0x07,
'a',
'b',
'c',
'-',
'b',
'i',
'n', 0x84,
572 0x7f, 0x4e, 0x29, 0x3f})};
581 return {
MakeSlice({0x00, 0x07,
'a',
'b',
'c',
'-',
'b',
582 'i',
'n', 0x8b, 0x71, 0x0c, 0xa5, 0x81,
583 0x73, 0x7b, 0x47, 0x13, 0xe9, 0xf7, 0xe3})};
592 return {
MakeSlice({0x00, 0x07,
'a',
'b',
'c',
'-',
'b',
'i',
'n',
593 0xa3, 0x92, 0x43, 0x7f, 0xbe, 0x7c, 0xea, 0x6f, 0xf3,
594 0x3d, 0xa7, 0xa7, 0x67, 0xfb, 0xe2, 0x82, 0xf7, 0xf2,
595 0x8f, 0x1f, 0x9d, 0xdf, 0xf1, 0x7e, 0xb3, 0xef, 0xb2,
596 0x8f, 0x53, 0x77, 0xce, 0x0c, 0x13, 0xe3, 0xfd, 0x87})};
606 {0x00, 0x07,
'a',
'b',
'c',
'-',
'b',
'i',
'n', 0xeb, 0x1d, 0x4d,
607 0xe8, 0x96, 0x8c, 0x14, 0x20, 0x06, 0xc1, 0xc3, 0xdf, 0x6e, 0x1f, 0xef,
608 0xde, 0x2f, 0xde, 0xb7, 0xf2, 0xfe, 0x6d, 0xd4, 0xe4, 0x7d, 0xf5, 0x55,
609 0x46, 0x52, 0x3d, 0x91, 0xf2, 0xd4, 0x6f, 0xca, 0x34, 0xcd, 0xd9, 0x39,
610 0xbd, 0x03, 0x27, 0xe3, 0x9c, 0x74, 0xcc, 0x17, 0x34, 0xed, 0xa6, 0x6a,
611 0x77, 0x73, 0x10, 0xcd, 0x8e, 0x4e, 0x5c, 0x7c, 0x72, 0x39, 0xd8, 0xe6,
612 0x78, 0x6b, 0xdb, 0xa5, 0xb7, 0xab, 0xe7, 0x46, 0xae, 0x21, 0xab, 0x7f,
613 0x01, 0x89, 0x13, 0xd7, 0xca, 0x17, 0x6e, 0xcb, 0xd6, 0x79, 0x71, 0x68,
614 0xbf, 0x8a, 0x3f, 0x32, 0xe8, 0xba, 0xf5, 0xbe, 0xb3, 0xbc, 0xde, 0x28,
615 0xc7, 0xcf, 0x62, 0x7a, 0x58, 0x2c, 0xcf, 0x4d, 0xe3})};
638 return {
MakeSlice({0x0f, 0x2f, 0x03,
'3',
'0',
'S'})};
684 int main(
int argc,
char** argv) {