proxygen
IPAddressBenchmark.cpp File Reference
#include <folly/Format.h>
#include <folly/IPAddress.h>
#include <glog/logging.h>
#include <folly/Benchmark.h>

Go to the source code of this file.

Functions

 BENCHMARK (ipv4_to_string_inet_ntop, iters)
 
 BENCHMARK_RELATIVE (ipv4_to_fully_qualified, iters)
 
 BENCHMARK_DRAW_LINE ()
 
 BENCHMARK (ipv4_to_fully_qualified_port, iters)
 
 BENCHMARK_RELATIVE (ipv4_append_to_fully_qualified_port, iters)
 
 BENCHMARK (ipv6_to_string_inet_ntop, iters)
 
 BENCHMARK_RELATIVE (ipv6_to_fully_qualified, iters)
 
 BENCHMARK (ipv6_to_fully_qualified_port, iters)
 
 BENCHMARK_RELATIVE (ipv6_append_to_fully_qualified_port, iters)
 
 BENCHMARK (ipv6_ctor_valid, iters)
 
 BENCHMARK_RELATIVE (ipv6_ctor_invalid, iters)
 
 BENCHMARK (ipv6_try_from_string_valid, iters)
 
 BENCHMARK_RELATIVE (ipv6_try_from_string_invalid, iters)
 
int main (int argc, char *argv[])
 

Function Documentation

BENCHMARK ( ipv4_to_string_inet_ntop  ,
iters   
)

Definition at line 27 of file IPAddressBenchmark.cpp.

References folly::doNotOptimizeAway(), folly::IPAddressV4::toAddr(), and val.

27  {
28  folly::IPAddressV4 ipv4Addr("127.0.0.1");
29  in_addr ip = ipv4Addr.toAddr();
30  char outputString[INET_ADDRSTRLEN] = {0};
31 
32  while (iters--) {
33  const char* val =
34  inet_ntop(AF_INET, &ip, outputString, sizeof(outputString));
36  }
37 }
double val
Definition: String.cpp:273
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( ipv4_to_fully_qualified_port  ,
iters   
)

Definition at line 50 of file IPAddressBenchmark.cpp.

References folly::doNotOptimizeAway(), folly::sformat(), and folly::IPAddressV4::toFullyQualified().

50  {
51  IPAddressV4 ip("255.255.255.255");
52  while (iters--) {
53  string outputString = folly::sformat("{}:{}", ip.toFullyQualified(), 65535);
54  folly::doNotOptimizeAway(outputString);
55  folly::doNotOptimizeAway(outputString.data());
56  }
57 }
std::string sformat(StringPiece fmt, Args &&...args)
Definition: Format.h:280
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( ipv6_to_string_inet_ntop  ,
iters   
)

Definition at line 74 of file IPAddressBenchmark.cpp.

References folly::doNotOptimizeAway(), folly::IPAddressV6::toAddr(), and val.

74  {
75  IPAddressV6 ipv6Addr("F1E0:0ACE:FB94:7ADF:22E8:6DE6:9672:3725");
76  in6_addr ip = ipv6Addr.toAddr();
77  char outputString[INET6_ADDRSTRLEN] = {0};
78 
79  while (iters--) {
80  const char* val =
81  inet_ntop(AF_INET6, &ip, outputString, sizeof(outputString));
83  }
84 }
double val
Definition: String.cpp:273
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( ipv6_to_fully_qualified_port  ,
iters   
)

Definition at line 97 of file IPAddressBenchmark.cpp.

References folly::doNotOptimizeAway(), folly::sformat(), and folly::IPAddressV6::toFullyQualified().

97  {
98  IPAddressV6 ip("F1E0:0ACE:FB94:7ADF:22E8:6DE6:9672:3725");
99  while (iters--) {
100  string outputString = folly::sformat("{}:{}", ip.toFullyQualified(), 65535);
101  folly::doNotOptimizeAway(outputString);
102  folly::doNotOptimizeAway(outputString.data());
103  }
104 }
std::string sformat(StringPiece fmt, Args &&...args)
Definition: Format.h:280
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( ipv6_ctor_valid  ,
iters   
)

Definition at line 121 of file IPAddressBenchmark.cpp.

References folly::doNotOptimizeAway().

121  {
122  while (iters--) {
123  try {
124  IPAddressV6 ip("2803:6082:18e0:2c49:1a23:9ee0:5c87:9800");
125  doNotOptimizeAway(ip);
126  } catch (const IPAddressFormatException& ex) {
127  doNotOptimizeAway(ex);
128  }
129  }
130 }
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( ipv6_try_from_string_valid  ,
iters   
)

Definition at line 145 of file IPAddressBenchmark.cpp.

References folly::doNotOptimizeAway(), and folly::IPAddressV6::tryFromString().

145  {
146  while (iters--) {
147  auto maybeIp =
148  IPAddressV6::tryFromString("2803:6082:18e0:2c49:1a23:9ee0:5c87:9800");
149  CHECK(maybeIp.hasValue());
150  doNotOptimizeAway(maybeIp);
151  doNotOptimizeAway(maybeIp.value());
152  }
153 }
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK_DRAW_LINE ( )
BENCHMARK_RELATIVE ( ipv4_to_fully_qualified  ,
iters   
)

Definition at line 39 of file IPAddressBenchmark.cpp.

References folly::BENCHMARK_DRAW_LINE(), folly::doNotOptimizeAway(), and folly::IPAddressV4::toFullyQualified().

39  {
40  IPAddressV4 ip("127.0.0.1");
41  while (iters--) {
42  string outputString = ip.toFullyQualified();
43  folly::doNotOptimizeAway(outputString);
44  folly::doNotOptimizeAway(outputString.data());
45  }
46 }
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK_RELATIVE ( ipv4_append_to_fully_qualified_port  ,
iters   
)

Definition at line 59 of file IPAddressBenchmark.cpp.

References folly::BENCHMARK_DRAW_LINE(), folly::doNotOptimizeAway(), folly::IPAddressV4::kMaxToFullyQualifiedSize, folly::toAppend(), and folly::IPAddressV4::toFullyQualifiedAppend().

59  {
60  IPAddressV4 ip("255.255.255.255");
61  while (iters--) {
62  string outputString;
63  outputString.reserve(IPAddressV4::kMaxToFullyQualifiedSize + 1 + 5);
64  ip.toFullyQualifiedAppend(outputString);
65  outputString += ':';
66  folly::toAppend(65535, &outputString);
67  folly::doNotOptimizeAway(outputString);
68  folly::doNotOptimizeAway(outputString.data());
69  }
70 }
void toAppend(char value, Tgt *result)
Definition: Conv.h:406
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK_RELATIVE ( ipv6_to_fully_qualified  ,
iters   
)

Definition at line 86 of file IPAddressBenchmark.cpp.

References folly::BENCHMARK_DRAW_LINE(), folly::doNotOptimizeAway(), and folly::IPAddressV6::toFullyQualified().

86  {
87  IPAddressV6 ip("F1E0:0ACE:FB94:7ADF:22E8:6DE6:9672:3725");
88  while (iters--) {
89  string outputString = ip.toFullyQualified();
90  folly::doNotOptimizeAway(outputString);
91  folly::doNotOptimizeAway(outputString.data());
92  }
93 }
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK_RELATIVE ( ipv6_append_to_fully_qualified_port  ,
iters   
)

Definition at line 106 of file IPAddressBenchmark.cpp.

References folly::BENCHMARK_DRAW_LINE(), folly::doNotOptimizeAway(), folly::IPAddressV6::kToFullyQualifiedSize, folly::toAppend(), and folly::IPAddressV6::toFullyQualifiedAppend().

106  {
107  IPAddressV6 ip("F1E0:0ACE:FB94:7ADF:22E8:6DE6:9672:3725");
108  while (iters--) {
109  string outputString;
110  outputString.reserve(folly::IPAddressV6::kToFullyQualifiedSize + 1 + 5);
111  ip.toFullyQualifiedAppend(outputString);
112  outputString += ':';
113  folly::toAppend(65535, &outputString);
114  folly::doNotOptimizeAway(outputString);
115  folly::doNotOptimizeAway(outputString.data());
116  }
117 }
static constexpr size_t kToFullyQualifiedSize
Definition: IPAddressV6.h:93
void toAppend(char value, Tgt *result)
Definition: Conv.h:406
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK_RELATIVE ( ipv6_ctor_invalid  ,
iters   
)

Definition at line 132 of file IPAddressBenchmark.cpp.

References folly::BENCHMARK_DRAW_LINE(), and folly::doNotOptimizeAway().

132  {
133  while (iters--) {
134  try {
135  IPAddressV6 ip("2803:6082:18e0:2c49:1a23:9ee0:5c87:980r");
136  doNotOptimizeAway(ip);
137  } catch (const IPAddressFormatException& ex) {
138  doNotOptimizeAway(ex);
139  }
140  }
141 }
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK_RELATIVE ( ipv6_try_from_string_invalid  ,
iters   
)

Definition at line 155 of file IPAddressBenchmark.cpp.

References folly::doNotOptimizeAway(), and folly::IPAddressV6::tryFromString().

155  {
156  while (iters--) {
157  auto maybeIp =
158  IPAddressV6::tryFromString("2803:6082:18e0:2c49:1a23:9ee0:5c87:980r");
159  CHECK(maybeIp.hasError());
160  doNotOptimizeAway(maybeIp);
161  doNotOptimizeAway(maybeIp.error());
162  }
163 }
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
int main ( int  argc,
char *  argv[] 
)

Definition at line 188 of file IPAddressBenchmark.cpp.

References folly::runBenchmarks().

188  {
189  gflags::ParseCommandLineFlags(&argc, &argv, true);
190  runBenchmarks();
191  return 0;
192 }
void runBenchmarks()
Definition: Benchmark.cpp:456
char ** argv