| 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 <iostream> |
| 23 |
|
| 24 |
#include <benchmark/benchmark.h> |
| 25 |
|
| 26 |
#include <proton/connection_options.hpp> |
| 27 |
#include <proton/container.hpp> |
| 28 |
#include <proton/messaging_handler.hpp> |
| 29 |
|
| 30 |
// PROTON-2137 [cpp] Performance regression found in 0.29.0 |
| 31 |
// proton would spend long time initializing ssl when not needed |
| 32 |
|
| 33 |
class handler : public proton::messaging_handler { |
| 34 |
std::string url; |
| 35 |
|
| 36 |
public: |
| 37 |
explicit handler(const std::string &u) : url(u) {} |
| 38 |
|
| 39 |
private: |
| 40 |
void on_container_start(proton::container &c) override { |
| 41 |
c.connect(url, proton::connection_options().sasl_enabled(false)); |
| 42 |
} |
| 43 |
|
| 44 |
void on_connection_open(proton::connection &c) override { c.close(); } |
| 45 |
}; |
| 46 |
|
| 47 |
// expected to run in < 1 ms, for me it is 160 us |
| 48 |
static void BM_UnsuccessfulContainerRun(benchmark::State &state) { |
| 49 |
for (auto _ : state) { |
| 50 |
try { |
| 51 |
handler h("127.0.0.1:0"); // wrong port |
| 52 |
proton::container(h).run(); |
| 53 |
state.SkipWithError("Exception expected"); |
| 54 |
} catch (std::exception &e) { |
| 55 |
// expected |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
BENCHMARK(BM_UnsuccessfulContainerRun)->Unit(benchmark::kMicrosecond); |