14 #include <unordered_map> 16 using namespace folly;
38 std::vector<HTTPHeaderCode> getTestHeaderCodes() {
39 std::vector<HTTPHeaderCode> testHeaderCodes;
41 j < HTTPCommonHeaders::num_header_codes; ++j) {
42 testHeaderCodes.push_back(static_cast<HTTPHeaderCode>(j));
44 return testHeaderCodes;
47 std::vector<const std::string *> getTestHeaderCodeStrings() {
48 std::vector<const std::string *> testHeadersCodeStrings;
50 j < HTTPCommonHeaders::num_header_codes; ++j) {
51 testHeadersCodeStrings.push_back(
52 HTTPCommonHeaders::getPointerToHeaderName(
53 static_cast<HTTPHeaderCode>(j)));
55 return testHeadersCodeStrings;
58 std::vector<const std::string *> getTestHeaderOtherStrings() {
59 std::vector<const std::string *> testHeadersOtherStrings;
61 j < HTTPCommonHeaders::num_header_codes; ++j) {
62 testHeadersOtherStrings.push_back(
64 *HTTPCommonHeaders::getPointerToHeaderName(
65 static_cast<HTTPHeaderCode>(j))
68 return testHeadersOtherStrings;
71 static const std::vector<HTTPHeaderCode> testHeaderCodes = getTestHeaderCodes();
73 static const std::vector<const std::string *> testHeadersCodeStrings =
74 getTestHeaderCodeStrings();
76 static const std::vector<const std::string *> testHeadersOtherStrings =
77 getTestHeaderOtherStrings();
83 HTTPCommonHeaders::hash,
86 DefaultPerfectIndexMap;
91 std::unordered_map<std::string,std::string>&
testMap,
92 const std::vector<const std::string *>& keysAndValues,
int iters) {
93 for (
int i = 0;
i < iters; ++
i) {
94 for (
auto const& keyAndValue: keysAndValues) {
96 testMap[*keyAndValue] = *keyAndValue;
102 DefaultPerfectIndexMap &
map,
const std::vector<HTTPHeaderCode>& keys,
103 const std::vector<const std::string *>&
values,
int iters) {
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]);
112 DefaultPerfectIndexMap &
map,
113 const std::vector<const std::string *>& keysAndValues,
int iters) {
114 for (
int i = 0;
i < iters; ++
i) {
115 for (
auto const& keyAndValue: keysAndValues) {
116 map.set(*keyAndValue, *keyAndValue);
122 std::unordered_map<std::string,std::string>&
testMap,
123 const std::vector<const std::string *>& keys,
int iters) {
124 for (
int i = 0;
i < iters; ++
i) {
125 for (
auto const& key: keys) {
127 auto it = testMap.find(*key);
129 it == testMap.end() ?
137 DefaultPerfectIndexMap &
map,
const std::vector<HTTPHeaderCode>& keys,
139 for (
int i = 0;
i < iters; ++
i) {
140 for (
auto const& key: keys) {
147 DefaultPerfectIndexMap &
map,
const std::vector<const std::string *>& keys,
149 for (
int i = 0;
i < iters; ++
i) {
150 for (
auto const& key: keys) {
159 bUnorderedMapUniqueInsertsMap, testHeadersCodeStrings, iters);
162 std::unordered_map<std::string, std::string>
164 std::unordered_map<std::string, std::string>
testMap;
172 bUnorderedMapUniqueGetsMap, testHeadersCodeStrings, iters);
178 bPerfectIndexMapUniqueInsertsCodeMap, testHeaderCodes,
179 testHeadersCodeStrings, iters);
182 DefaultPerfectIndexMap
184 BENCHMARK(PerfectIndexMapUniqueInsertsHashCodeString, iters) {
190 DefaultPerfectIndexMap
192 BENCHMARK(PerfectIndexMapUniqueInsertsHashOtherString, iters) {
195 testHeadersOtherStrings, iters);
199 DefaultPerfectIndexMap
testMap;
201 testMap, testHeaderCodes, testHeadersCodeStrings, 1);
208 bPerfectIndexMapUniqueGetsCodeMap, testHeaderCodes, iters);
215 bPerfectIndexMapUniqueGetsCodeStringMap, testHeadersCodeStrings, iters);
219 DefaultPerfectIndexMap
testMap;
225 BENCHMARK(PerfectIndexMapUniqueGetsOtherString, iters) {
227 bPerfectIndexMapUniqueGetsOtherStringMap, testHeadersOtherStrings, iters);
231 gflags::ParseCommandLineFlags(&argc, &argv,
true);
235 for (
auto * testHeaderOtherString: testHeadersOtherStrings) {
236 delete testHeaderOtherString;
void PerfectIndexMapInsertHashBench(DefaultPerfectIndexMap &map, const std::vector< const std::string * > &keysAndValues, int iters)
DefaultPerfectIndexMap bPerfectIndexMapUniqueGetsCodeStringMap
std::unordered_map< std::string, std::string > getBenchUnorderedMapUniqueGetsTestMap()
DefaultPerfectIndexMap bPerfectIndexMapUniqueGetsOtherStringMap
DefaultPerfectIndexMap bPerfectIndexMapUniqueInsertsHashOtherStringTestMap
DefaultPerfectIndexMap bPerfectIndexMapUniqueInsertsCodeMap
void UnorderedMapGetBench(std::unordered_map< std::string, std::string > &testMap, const std::vector< const std::string * > &keys, int iters)
DefaultPerfectIndexMap getBenchPerfectIndexMapUniqueGetsOtherStringTestMap()
DefaultPerfectIndexMap getBenchPerfectIndexMapUniqueGetsCodeTestMap()
—— Concurrent Priority Queue Implementation ——
int main(int argc, char **argv)
std::unordered_map< std::string, std::string > bUnorderedMapUniqueGetsMap
void PerfectIndexMapInsertCodeBench(DefaultPerfectIndexMap &map, const std::vector< HTTPHeaderCode > &keys, const std::vector< const std::string * > &values, 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)
DefaultPerfectIndexMap bPerfectIndexMapUniqueGetsCodeMap
BENCHMARK(fbFollyGlobalBenchmarkBaseline)
DefaultPerfectIndexMap bPerfectIndexMapUniqueInsertsHashCodeStringTestMap
const uint8_t HTTPHeaderCodeCommonOffset
std::unordered_map< std::string, std::string > bUnorderedMapUniqueInsertsMap
std::vector< int > values(1'000)
void UnorderedMapInsertBench(std::unordered_map< std::string, std::string > &testMap, const std::vector< const std::string * > &keysAndValues, int iters)