Debian Codegraph @

c/benchmarks/message-encoding.cpp

raw
1 /*
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 */
21
22 #include "proton/message.h"
23
24 #include <benchmark/benchmark.h>
25 #include <core/data.h>
26 #include <proton/netaddr.h>
27
28 #include <cstdlib>
29 #include <cstring>
30
31 /** Initialize message, don't decode?
32 * Issues:
33 * PROTON-2229 pn_data_t initialization lead to low performance
34 */
35 static void BM_Encode10MbMessage(benchmark::State &state) {
36 const size_t size = 10 * 1024 * 1024;
37 char *payload = static_cast<char *>(malloc(size));
38 pn_bytes_t bytes = pn_bytes(size, payload);
39
40 for (auto _ : state) {
41 pn_message_t *message = pn_message();
42 pn_data_t *body = pn_message_body(message);
43 for (size_t i = 0; i < state.range(0); i++) {
44 pn_data_put_binary(body, bytes);
45 }
46
47 pn_message_free(message);
48 }
49
50 free(payload);
51 }
52
53 BENCHMARK(BM_Encode10MbMessage)
54 ->Arg(1)
55 ->Arg(2)
56 ->ArgName("put_binary count")
57 ->Unit(benchmark::kMillisecond);