proxygen
PerfectIndexMapBenchmark.cpp File Reference
#include <algorithm>
#include <folly/Benchmark.h>
#include <proxygen/lib/http/HTTPCommonHeaders.h>
#include <proxygen/lib/utils/PerfectIndexMap.h>
#include <unordered_map>

Go to the source code of this file.

Functions

void UnorderedMapInsertBench (std::unordered_map< std::string, std::string > &testMap, const std::vector< const std::string * > &keysAndValues, int iters)
 
void PerfectIndexMapInsertCodeBench (DefaultPerfectIndexMap &map, const std::vector< HTTPHeaderCode > &keys, const std::vector< const std::string * > &values, int iters)
 
void PerfectIndexMapInsertHashBench (DefaultPerfectIndexMap &map, const std::vector< const std::string * > &keysAndValues, int iters)
 
void UnorderedMapGetBench (std::unordered_map< std::string, std::string > &testMap, const std::vector< const std::string * > &keys, int iters)
 
void PerfectIndexMapGetCodeBench (DefaultPerfectIndexMap &map, const std::vector< HTTPHeaderCode > &keys, int iters)
 
void PerfectIndexMapGetStringBench (DefaultPerfectIndexMap &map, const std::vector< const std::string * > &keys, int iters)
 
 BENCHMARK (UnorderedMapUniqueInserts, iters)
 
std::unordered_map< std::string, std::stringgetBenchUnorderedMapUniqueGetsTestMap ()
 
 BENCHMARK (UnorderedMapUniqueGets, iters)
 
 BENCHMARK (PerfectIndexMapUniqueInsertsCode, iters)
 
 BENCHMARK (PerfectIndexMapUniqueInsertsHashCodeString, iters)
 
 BENCHMARK (PerfectIndexMapUniqueInsertsHashOtherString, iters)
 
DefaultPerfectIndexMap getBenchPerfectIndexMapUniqueGetsCodeTestMap ()
 
 BENCHMARK (PerfectIndexMapUniqueGetsCode, iters)
 
 BENCHMARK (PerfectIndexMapUniqueGetsCodeString, iters)
 
DefaultPerfectIndexMap getBenchPerfectIndexMapUniqueGetsOtherStringTestMap ()
 
 BENCHMARK (PerfectIndexMapUniqueGetsOtherString, iters)
 
int main (int argc, char **argv)
 

Variables

std::unordered_map< std::string, std::stringbUnorderedMapUniqueInsertsMap
 
std::unordered_map< std::string, std::stringbUnorderedMapUniqueGetsMap
 
DefaultPerfectIndexMap bPerfectIndexMapUniqueInsertsCodeMap
 
DefaultPerfectIndexMap bPerfectIndexMapUniqueInsertsHashCodeStringTestMap
 
DefaultPerfectIndexMap bPerfectIndexMapUniqueInsertsHashOtherStringTestMap
 
DefaultPerfectIndexMap bPerfectIndexMapUniqueGetsCodeMap
 
DefaultPerfectIndexMap bPerfectIndexMapUniqueGetsCodeStringMap
 
DefaultPerfectIndexMap bPerfectIndexMapUniqueGetsOtherStringMap
 

Function Documentation

BENCHMARK ( UnorderedMapUniqueInserts  ,
iters   
)

Definition at line 157 of file PerfectIndexMapBenchmark.cpp.

References UnorderedMapInsertBench().

157  {
159  bUnorderedMapUniqueInsertsMap, testHeadersCodeStrings, iters);
160 }
std::unordered_map< std::string, std::string > bUnorderedMapUniqueInsertsMap
void UnorderedMapInsertBench(std::unordered_map< std::string, std::string > &testMap, const std::vector< const std::string * > &keysAndValues, int iters)
BENCHMARK ( UnorderedMapUniqueGets  ,
iters   
)

Definition at line 170 of file PerfectIndexMapBenchmark.cpp.

References UnorderedMapGetBench().

170  {
172  bUnorderedMapUniqueGetsMap, testHeadersCodeStrings, iters);
173 }
void UnorderedMapGetBench(std::unordered_map< std::string, std::string > &testMap, const std::vector< const std::string * > &keys, int iters)
std::unordered_map< std::string, std::string > bUnorderedMapUniqueGetsMap
BENCHMARK ( PerfectIndexMapUniqueInsertsCode  ,
iters   
)

Definition at line 176 of file PerfectIndexMapBenchmark.cpp.

References PerfectIndexMapInsertCodeBench().

176  {
178  bPerfectIndexMapUniqueInsertsCodeMap, testHeaderCodes,
179  testHeadersCodeStrings, iters);
180 }
DefaultPerfectIndexMap bPerfectIndexMapUniqueInsertsCodeMap
void PerfectIndexMapInsertCodeBench(DefaultPerfectIndexMap &map, const std::vector< HTTPHeaderCode > &keys, const std::vector< const std::string * > &values, int iters)
BENCHMARK ( PerfectIndexMapUniqueInsertsHashCodeString  ,
iters   
)

Definition at line 184 of file PerfectIndexMapBenchmark.cpp.

References bPerfectIndexMapUniqueInsertsHashCodeStringTestMap, and PerfectIndexMapInsertHashBench().

184  {
187  iters);
188 }
void PerfectIndexMapInsertHashBench(DefaultPerfectIndexMap &map, const std::vector< const std::string * > &keysAndValues, int iters)
DefaultPerfectIndexMap bPerfectIndexMapUniqueInsertsHashCodeStringTestMap
BENCHMARK ( PerfectIndexMapUniqueInsertsHashOtherString  ,
iters   
)

Definition at line 192 of file PerfectIndexMapBenchmark.cpp.

References bPerfectIndexMapUniqueInsertsHashOtherStringTestMap, and PerfectIndexMapInsertHashBench().

192  {
195  testHeadersOtherStrings, iters);
196 }
void PerfectIndexMapInsertHashBench(DefaultPerfectIndexMap &map, const std::vector< const std::string * > &keysAndValues, int iters)
DefaultPerfectIndexMap bPerfectIndexMapUniqueInsertsHashOtherStringTestMap
BENCHMARK ( PerfectIndexMapUniqueGetsCode  ,
iters   
)

Definition at line 206 of file PerfectIndexMapBenchmark.cpp.

References PerfectIndexMapGetCodeBench().

206  {
208  bPerfectIndexMapUniqueGetsCodeMap, testHeaderCodes, iters);
209 }
void PerfectIndexMapGetCodeBench(DefaultPerfectIndexMap &map, const std::vector< HTTPHeaderCode > &keys, int iters)
DefaultPerfectIndexMap bPerfectIndexMapUniqueGetsCodeMap
BENCHMARK ( PerfectIndexMapUniqueGetsCodeString  ,
iters   
)

Definition at line 213 of file PerfectIndexMapBenchmark.cpp.

References PerfectIndexMapGetStringBench().

213  {
215  bPerfectIndexMapUniqueGetsCodeStringMap, testHeadersCodeStrings, iters);
216 }
DefaultPerfectIndexMap bPerfectIndexMapUniqueGetsCodeStringMap
void PerfectIndexMapGetStringBench(DefaultPerfectIndexMap &map, const std::vector< const std::string * > &keys, int iters)
BENCHMARK ( PerfectIndexMapUniqueGetsOtherString  ,
iters   
)

Definition at line 225 of file PerfectIndexMapBenchmark.cpp.

References PerfectIndexMapGetStringBench().

225  {
227  bPerfectIndexMapUniqueGetsOtherStringMap, testHeadersOtherStrings, iters);
228 }
DefaultPerfectIndexMap bPerfectIndexMapUniqueGetsOtherStringMap
void PerfectIndexMapGetStringBench(DefaultPerfectIndexMap &map, const std::vector< const std::string * > &keys, int iters)
DefaultPerfectIndexMap getBenchPerfectIndexMapUniqueGetsCodeTestMap ( )

Definition at line 198 of file PerfectIndexMapBenchmark.cpp.

References PerfectIndexMapInsertCodeBench(), and testMap().

198  {
199  DefaultPerfectIndexMap testMap;
201  testMap, testHeaderCodes, testHeadersCodeStrings, 1);
202  return testMap;
203 }
void testMap()
void PerfectIndexMapInsertCodeBench(DefaultPerfectIndexMap &map, const std::vector< HTTPHeaderCode > &keys, const std::vector< const std::string * > &values, int iters)
DefaultPerfectIndexMap getBenchPerfectIndexMapUniqueGetsOtherStringTestMap ( )

Definition at line 218 of file PerfectIndexMapBenchmark.cpp.

References PerfectIndexMapInsertHashBench(), and testMap().

218  {
219  DefaultPerfectIndexMap testMap;
220  PerfectIndexMapInsertHashBench(testMap, testHeadersOtherStrings, 1);
221  return testMap;
222 }
void PerfectIndexMapInsertHashBench(DefaultPerfectIndexMap &map, const std::vector< const std::string * > &keysAndValues, int iters)
void testMap()
std::unordered_map<std::string, std::string> getBenchUnorderedMapUniqueGetsTestMap ( )

Definition at line 163 of file PerfectIndexMapBenchmark.cpp.

References testMap(), and UnorderedMapInsertBench().

163  {
164  std::unordered_map<std::string, std::string> testMap;
165  UnorderedMapInsertBench(testMap, testHeadersCodeStrings, 1);
166  return testMap;
167 }
void testMap()
void UnorderedMapInsertBench(std::unordered_map< std::string, std::string > &testMap, const std::vector< const std::string * > &keysAndValues, int iters)
int main ( int  argc,
char **  argv 
)

Definition at line 230 of file PerfectIndexMapBenchmark.cpp.

References folly::runBenchmarks().

230  {
231  gflags::ParseCommandLineFlags(&argc, &argv, true);
233 
234  // Not explicitly required but lets free memory we specifically allocated.
235  for (auto * testHeaderOtherString: testHeadersOtherStrings) {
236  delete testHeaderOtherString;
237  }
238 
239  return 0;
240 }
void runBenchmarks()
Definition: Benchmark.cpp:456
char ** argv
void PerfectIndexMapGetCodeBench ( DefaultPerfectIndexMap &  map,
const std::vector< HTTPHeaderCode > &  keys,
int  iters 
)

Definition at line 136 of file PerfectIndexMapBenchmark.cpp.

References i, and folly::none.

Referenced by BENCHMARK().

138  {
139  for (int i = 0; i < iters; ++i) {
140  for (auto const& key: keys) {
141  CHECK(map.getSingleOrNone(key) != folly::none);
142  }
143  }
144 }
Definition: Traits.h:594
constexpr None none
Definition: Optional.h:87
void PerfectIndexMapGetStringBench ( DefaultPerfectIndexMap &  map,
const std::vector< const std::string * > &  keys,
int  iters 
)

Definition at line 146 of file PerfectIndexMapBenchmark.cpp.

References i, and folly::none.

Referenced by BENCHMARK().

148  {
149  for (int i = 0; i < iters; ++i) {
150  for (auto const& key: keys) {
151  CHECK(map.getSingleOrNone(*key) != folly::none);
152  }
153  }
154 }
Definition: Traits.h:594
constexpr None none
Definition: Optional.h:87
void PerfectIndexMapInsertCodeBench ( DefaultPerfectIndexMap &  map,
const std::vector< HTTPHeaderCode > &  keys,
const std::vector< const std::string * > &  values,
int  iters 
)

Definition at line 101 of file PerfectIndexMapBenchmark.cpp.

References i.

Referenced by BENCHMARK(), and getBenchPerfectIndexMapUniqueGetsCodeTestMap().

103  {
104  for (int i = 0; i < iters; ++i) {
105  for (unsigned long j = 0; j < keys.size(); ++j) {
106  map.set(keys[j], *values[j]);
107  }
108  }
109 }
Definition: Traits.h:594
void PerfectIndexMapInsertHashBench ( DefaultPerfectIndexMap &  map,
const std::vector< const std::string * > &  keysAndValues,
int  iters 
)

Definition at line 111 of file PerfectIndexMapBenchmark.cpp.

References i.

Referenced by BENCHMARK(), and getBenchPerfectIndexMapUniqueGetsOtherStringTestMap().

113  {
114  for (int i = 0; i < iters; ++i) {
115  for (auto const& keyAndValue: keysAndValues) {
116  map.set(*keyAndValue, *keyAndValue);
117  }
118  }
119 }
Definition: Traits.h:594
void UnorderedMapGetBench ( std::unordered_map< std::string, std::string > &  testMap,
const std::vector< const std::string * > &  keys,
int  iters 
)

Definition at line 121 of file PerfectIndexMapBenchmark.cpp.

References i, and folly::none.

Referenced by BENCHMARK().

123  {
124  for (int i = 0; i < iters; ++i) {
125  for (auto const& key: keys) {
126  // Modeled after old impl of varstore
127  auto it = testMap.find(*key);
129  it == testMap.end() ?
131  CHECK(result != folly::none);
132  }
133  }
134 }
constexpr None none
Definition: Optional.h:87
void UnorderedMapInsertBench ( std::unordered_map< std::string, std::string > &  testMap,
const std::vector< const std::string * > &  keysAndValues,
int  iters 
)

Definition at line 90 of file PerfectIndexMapBenchmark.cpp.

References i.

Referenced by BENCHMARK(), and getBenchUnorderedMapUniqueGetsTestMap().

92  {
93  for (int i = 0; i < iters; ++i) {
94  for (auto const& keyAndValue: keysAndValues) {
95  // Modeled after old impl of varstore
96  testMap[*keyAndValue] = *keyAndValue;
97  }
98  }
99 }

Variable Documentation

DefaultPerfectIndexMap bPerfectIndexMapUniqueGetsCodeMap
Initial value:
=
DefaultPerfectIndexMap getBenchPerfectIndexMapUniqueGetsCodeTestMap()

Definition at line 204 of file PerfectIndexMapBenchmark.cpp.

DefaultPerfectIndexMap bPerfectIndexMapUniqueGetsCodeStringMap
Initial value:
=
DefaultPerfectIndexMap getBenchPerfectIndexMapUniqueGetsCodeTestMap()

Definition at line 211 of file PerfectIndexMapBenchmark.cpp.

DefaultPerfectIndexMap bPerfectIndexMapUniqueGetsOtherStringMap
Initial value:
=
DefaultPerfectIndexMap getBenchPerfectIndexMapUniqueGetsOtherStringTestMap()

Definition at line 223 of file PerfectIndexMapBenchmark.cpp.

DefaultPerfectIndexMap bPerfectIndexMapUniqueInsertsCodeMap

Definition at line 175 of file PerfectIndexMapBenchmark.cpp.

DefaultPerfectIndexMap bPerfectIndexMapUniqueInsertsHashCodeStringTestMap

Definition at line 183 of file PerfectIndexMapBenchmark.cpp.

Referenced by BENCHMARK().

DefaultPerfectIndexMap bPerfectIndexMapUniqueInsertsHashOtherStringTestMap

Definition at line 191 of file PerfectIndexMapBenchmark.cpp.

Referenced by BENCHMARK().

std::unordered_map<std::string, std::string> bUnorderedMapUniqueGetsMap
Initial value:
=
std::unordered_map< std::string, std::string > getBenchUnorderedMapUniqueGetsTestMap()

Definition at line 168 of file PerfectIndexMapBenchmark.cpp.

std::unordered_map<std::string, std::string> bUnorderedMapUniqueInsertsMap

Definition at line 156 of file PerfectIndexMapBenchmark.cpp.