Skip to content

Commit

Permalink
optimize include path
Browse files Browse the repository at this point in the history
  • Loading branch information
firedtoad committed Dec 17, 2023
1 parent b503897 commit a2187e2
Show file tree
Hide file tree
Showing 34 changed files with 244 additions and 132 deletions.
6 changes: 1 addition & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ set(CMAKE_VERBOSE_MAKEFILE ON)
include_directories(
/usr/local/include
${CMAKE_CURRENT_SOURCE_DIR}/lib3rd/
${CMAKE_CURRENT_SOURCE_DIR}/lib3rd/flat_hash_map
${CMAKE_CURRENT_SOURCE_DIR}/lib3rd/llvm
${CMAKE_CURRENT_SOURCE_DIR}/lib3rd/parallel_hashmap
${CMAKE_CURRENT_SOURCE_DIR}/lib3rd/sparsepp
${CMAKE_CURRENT_SOURCE_DIR}/lib3rd/robin_hood
${CMAKE_CURRENT_SOURCE_DIR}/lib3rd/openssl
)

link_directories(${CMAKE_CURRENT_SOURCE_DIR}/lib3rd/libs /usr/local/lib)
Expand Down
9 changes: 7 additions & 2 deletions src/adt/container/list/insert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,17 @@ static void BenchListInsert(benchmark::State &state)

BENCHMARK(BenchListInsert)->Range(1, 65536);

struct BUNode : public SList, public butil::LinkNode<BUNode>
{
int x{};
};

static void BenchBUListInsert(benchmark::State &state)
{
for (auto _ : state)
{
butil::LinkedList<SList> v;
std::vector<butil::LinkNode<SList>> vs;
butil::LinkedList<BUNode> v;
std::vector<BUNode> vs;
vs.resize(state.range(0));
for (auto i = 0; i < state.range(0); i++)
{
Expand Down
8 changes: 4 additions & 4 deletions src/adt/container/map/reserve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
#include <benchmark/benchmark.h>
#include <unordered_map>

#include "bytell_hash_map.hpp"
#include "flat_hash_map.hpp"
#include "flat_hash_map/bytell_hash_map.hpp"
#include "flat_hash_map/flat_hash_map.hpp"
#include "parallel_hashmap/phmap.h"
#include "robin_hood.h"
#include "robin_hood/robin_hood.h"
#include "sparsepp/spp.h"
#include "tsl/bhopscotch_map.h"
#include "tsl/hopscotch_map.h"
#include "tsl/robin_map.h"
#include "tsl/sparse_map.h"
#include "unordered_map.hpp"
#include "flat_hash_map/unordered_map.hpp"
#include <llvm/ADT/DenseMap.h>
#include <llvm/ADT/IndexedMap.h>
#include <llvm/ADT/IntervalMap.h>
Expand Down
8 changes: 4 additions & 4 deletions src/adt/container/map/unorder_erase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
// limitations under the License.
// Author dietoad@gmail.com && firedtoad@gmail.com

#include "bytell_hash_map.hpp"
#include "flat_hash_map.hpp"
#include "flat_hash_map/bytell_hash_map.hpp"
#include "flat_hash_map/flat_hash_map.hpp"
#include "parallel_hashmap/phmap.h"
#include "robin_hood.h"
#include "robin_hood/robin_hood.h"
#include "sparsepp/spp.h"
#include "tsl/array-hash/array_map.h"
#include "tsl/bhopscotch_map.h"
#include "tsl/hopscotch_map.h"
#include "tsl/htrie_map.h"
#include "tsl/robin_map.h"
#include "tsl/sparse_map.h"
#include "unordered_map.hpp"
#include "flat_hash_map/unordered_map.hpp"
#include <benchmark/benchmark.h>
#include <iostream>
#include <unordered_map>
Expand Down
8 changes: 4 additions & 4 deletions src/adt/container/map/unorder_find.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
// limitations under the License.
// Author dietoad@gmail.com && firedtoad@gmail.com

#include "bytell_hash_map.hpp"
#include "flat_hash_map.hpp"
#include "flat_hash_map/bytell_hash_map.hpp"
#include "flat_hash_map/flat_hash_map.hpp"
#include "parallel_hashmap/phmap.h"
#include "robin_hood.h"
#include "robin_hood/robin_hood.h"
#include "sparsepp/spp.h"
#include "tsl/array-hash/array_map.h"
#include "tsl/bhopscotch_map.h"
#include "tsl/hopscotch_map.h"
#include "tsl/htrie_map.h"
#include "tsl/robin_map.h"
#include "tsl/sparse_map.h"
#include "unordered_map.hpp"
#include "flat_hash_map/unordered_map.hpp"
#include <benchmark/benchmark.h>
#include <unordered_map>

Expand Down
8 changes: 4 additions & 4 deletions src/adt/container/map/unorder_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
// Author dietoad@gmail.com && firedtoad@gmail.com

#include "butil/containers/flat_map.h"
#include "bytell_hash_map.hpp"
#include "flat_hash_map.hpp"
#include "flat_hash_map/bytell_hash_map.hpp"
#include "flat_hash_map/flat_hash_map.hpp"
#include "parallel_hashmap/phmap.h"
#include "robin_hood.h"
#include "robin_hood/robin_hood.h"
#include "sparsepp/spp.h"
#include "tsl/array-hash/array_map.h"
#include "tsl/bhopscotch_map.h"
#include "tsl/hopscotch_map.h"
#include "tsl/htrie_map.h"
#include "tsl/robin_map.h"
#include "tsl/sparse_map.h"
#include "unordered_map.hpp"
#include "flat_hash_map/unordered_map.hpp"
#include <benchmark/benchmark.h>
#include <boost/container/flat_map.hpp>
#include <iostream>
Expand Down
8 changes: 4 additions & 4 deletions src/adt/container/set/unorder_erase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
// limitations under the License.
// Author dietoad@gmail.com && firedtoad@gmail.com

#include "bytell_hash_map.hpp"
#include "flat_hash_map.hpp"
#include "flat_hash_map/bytell_hash_map.hpp"
#include "flat_hash_map/flat_hash_map.hpp"
#include "parallel_hashmap/phmap.h"
#include "robin_hood.h"
#include "robin_hood/robin_hood.h"
#include "sparsepp/spp.h"
#include "tsl/array-hash/array_set.h"
#include "tsl/bhopscotch_set.h"
#include "tsl/hopscotch_set.h"
#include "tsl/htrie_set.h"
#include "tsl/robin_set.h"
#include "tsl/sparse_set.h"
#include "unordered_map.hpp"
#include "flat_hash_map/unordered_map.hpp"
#include <benchmark/benchmark.h>
#include <iostream>
#include <unordered_set>
Expand Down
8 changes: 4 additions & 4 deletions src/adt/container/set/unorder_find.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
// limitations under the License.
// Author dietoad@gmail.com && firedtoad@gmail.com

#include "bytell_hash_map.hpp"
#include "flat_hash_map.hpp"
#include "flat_hash_map/bytell_hash_map.hpp"
#include "flat_hash_map/flat_hash_map.hpp"
#include "parallel_hashmap/phmap.h"
#include "robin_hood.h"
#include "robin_hood/robin_hood.h"
#include "sparsepp/spp.h"
#include "tsl/array-hash/array_set.h"
#include "tsl/bhopscotch_set.h"
#include "tsl/hopscotch_set.h"
#include "tsl/htrie_set.h"
#include "tsl/robin_set.h"
#include "tsl/sparse_set.h"
#include "unordered_map.hpp"
#include "flat_hash_map/unordered_map.hpp"
#include <benchmark/benchmark.h>
#include <iostream>
#include <unordered_set>
Expand Down
8 changes: 4 additions & 4 deletions src/adt/container/set/unorder_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@
// limitations under the License.
// Author dietoad@gmail.com && firedtoad@gmail.com

#include "bytell_hash_map.hpp"
#include "flat_hash_map.hpp"
#include "flat_hash_map/bytell_hash_map.hpp"
#include "flat_hash_map/flat_hash_map.hpp"
#include "parallel_hashmap/phmap.h"
#include "robin_hood.h"
#include "robin_hood/robin_hood.h"
#include "sparsepp/spp.h"
#include "tsl/array-hash/array_set.h"
#include "tsl/bhopscotch_set.h"
#include "tsl/hopscotch_set.h"
#include "tsl/htrie_set.h"
#include "tsl/robin_set.h"
#include "tsl/sparse_set.h"
#include "unordered_map.hpp"
#include "flat_hash_map/unordered_map.hpp"
#include <benchmark/benchmark.h>
#include <iostream>
#include <unordered_set>
Expand Down
4 changes: 2 additions & 2 deletions src/adt/container/vfast/fast_unmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// Author dietoad@gmail.com && firedtoad@gmail.com

#include "container/FastVector.h"
#include "bytell_hash_map.hpp"
#include "flat_hash_map.hpp"
#include "flat_hash_map/bytell_hash_map.hpp"
#include "flat_hash_map/flat_hash_map.hpp"
#include "parallel_hashmap/phmap.h"
#include "tsl/robin_map.h"
#include <benchmark/benchmark.h>
Expand Down
4 changes: 2 additions & 2 deletions src/adt/container/vfast/fast_unset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// Author dietoad@gmail.com && firedtoad@gmail.com

#include "container/FastVector.h"
#include "bytell_hash_map.hpp"
#include "flat_hash_map.hpp"
#include "flat_hash_map/bytell_hash_map.hpp"
#include "flat_hash_map/flat_hash_map.hpp"
#include "parallel_hashmap/phmap.h"
#include "tsl/robin_set.h"
#include <benchmark/benchmark.h>
Expand Down
68 changes: 43 additions & 25 deletions src/container/hash/hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@
// Author dietoad@gmail.com && firedtoad@gmail.com

#include "butil/containers/flat_map.h"
#include "flat_hash_map.hpp"
#include "flat_hash_map/flat_hash_map.hpp"
#include "internal/city.h"
#include "internal/murmurhash3.h"
#include "internal/wyhash.h"
#include "internal/xxhash.h"
#include "parallel_hashmap/phmap.h"
#include "tsl/ordered_map.h"
#include "tsl/robin_map.h"
#include "tsl/sparse_map.h"
#include <absl/container/flat_hash_map.h>
#include <absl/hash/hash.h>
#include <benchmark/benchmark.h>
#include <fstream>
#include <string>
#include <vector>
constexpr int N = 1024;
Expand All @@ -50,12 +53,13 @@ static inline unsigned long random_()
return xorshf96();
}
std::vector<std::string> vec;

void init(std::vector<std::string> &v1)
{
v1.resize(N);
for (auto i = 0; i < N; i++)
{
v1[i] = std::to_string(random_())+std::to_string(random_()) + std::to_string(random_());
v1[i] = std::to_string(random_()) + std::to_string(random_()) + std::to_string(random_());
}
}

Expand All @@ -64,7 +68,7 @@ static void BM_StdHash(benchmark::State &state)
for (auto _ : state)
{
auto idx = random_() % vec.size();
auto r=std::_Hash_impl::hash(vec[idx]);
auto r = std::_Hash_impl::hash(vec[idx]);
benchmark::DoNotOptimize(r);
}
}
Expand All @@ -76,7 +80,7 @@ static void BM_StdHashFnv(benchmark::State &state)
for (auto _ : state)
{
auto idx = random_() % vec.size();
auto r=std::_Fnv_hash_impl::hash(vec[idx]);
auto r = std::_Fnv_hash_impl::hash(vec[idx]);
benchmark::DoNotOptimize(r);
}
}
Expand All @@ -88,7 +92,7 @@ static void BM_CityHash(benchmark::State &state)
for (auto _ : state)
{
auto idx = random_() % vec.size();
auto r = CityHash64(vec[idx].c_str(), vec[idx].size());
auto r = CityHash64(vec[idx].c_str(), vec[idx].size());
benchmark::DoNotOptimize(r);
}
}
Expand All @@ -113,7 +117,7 @@ static void BM_WyHash(benchmark::State &state)
for (auto _ : state)
{
auto idx = random_() % vec.size();
auto r = wyhash(vec[idx].c_str(), vec[idx].size(), 0, _wyp);
auto r = wyhash(vec[idx].c_str(), vec[idx].size(), 0, _wyp);
benchmark::DoNotOptimize(r);
}
}
Expand All @@ -125,7 +129,7 @@ static void BM_XXHash(benchmark::State &state)
for (auto _ : state)
{
auto idx = random_() % vec.size();
auto r = XXH64(vec[idx].c_str(), vec[idx].size(), 0);
auto r = XXH64(vec[idx].c_str(), vec[idx].size(), 0);
benchmark::DoNotOptimize(r);
}
}
Expand All @@ -137,7 +141,7 @@ static void BM_AbseilHash(benchmark::State &state)
for (auto _ : state)
{
auto idx = random_() % vec.size();
auto r = absl::Hash<std::string>{}(vec[idx]);
auto r = absl::Hash<std::string>{}(vec[idx]);
benchmark::DoNotOptimize(r);
}
}
Expand All @@ -149,7 +153,7 @@ static void BM_DefaultHash(benchmark::State &state)
for (auto _ : state)
{
auto idx = random_() % vec.size();
auto r = butil::DefaultHasher<std::string>{}(vec[idx]);
auto r = butil::DefaultHasher<std::string>{}(vec[idx]);
benchmark::DoNotOptimize(r);
}
}
Expand All @@ -169,19 +173,19 @@ struct Hasher
// return out;
}
};
std::vector<std::string> keys(65536);
std::vector<std::string> keys;
template <class M> static void BenchUnOrderMapString(benchmark::State &state)
{
M m;
m.reserve(65536);
m.reserve(keys.size());

for (auto i = 0; i < 65536; i++)
for (auto i = 0; i < keys.size(); i++)
{
m[keys[i]] = i;
}
for (auto _ : state)
{
auto kIndex = random_() % 65536;
auto kIndex = random_() % keys.size();
auto c = m.find(keys[kIndex]);
benchmark::DoNotOptimize(c);
}
Expand All @@ -198,35 +202,49 @@ BENCHMARK_TEMPLATE(BenchUnOrderMapString, absl::flat_hash_map<std::string, int,
BENCHMARK_TEMPLATE(BenchUnOrderMapString, absl::flat_hash_map<std::string, int, Hasher>);
BENCHMARK_TEMPLATE(BenchUnOrderMapString, tsl::robin_map<std::string, int>);
BENCHMARK_TEMPLATE(BenchUnOrderMapString, tsl::robin_map<std::string, int, Hasher>);
template <class M>
static void BenchFlatMapString(benchmark::State &state)
BENCHMARK_TEMPLATE(BenchUnOrderMapString, tsl::vector_map<std::string, int>);
BENCHMARK_TEMPLATE(BenchUnOrderMapString, tsl::vector_map<std::string, int, Hasher>);
BENCHMARK_TEMPLATE(BenchUnOrderMapString, tsl::sparse_map<std::string, int>);
BENCHMARK_TEMPLATE(BenchUnOrderMapString, tsl::sparse_map<std::string, int, Hasher>);

template <class M> static void BenchFlatMapString(benchmark::State &state)
{
M m;
m.init(65536);
for (auto i = 0; i < 65536; i++)
m.init(keys.size());
for (auto i = 0; i < keys.size(); i++)
{
m[keys[i]] = i;
}
for (auto _ : state)
{
auto kIndex = random_() % 65536;
auto kIndex = random_() % keys.size();
auto c = m.seek(keys[kIndex]);
benchmark::DoNotOptimize(c);
}
}

BENCHMARK_TEMPLATE(BenchFlatMapString,butil::FlatMap<std::string, int>);
BENCHMARK_TEMPLATE(BenchFlatMapString,butil::FlatMap<std::string, int, std::hash<std::string>>);
BENCHMARK_TEMPLATE(BenchFlatMapString,butil::FlatMap<std::string,int, Hasher>);

BENCHMARK_TEMPLATE(BenchFlatMapString, butil::FlatMap<std::string, int>);
BENCHMARK_TEMPLATE(BenchFlatMapString, butil::FlatMap<std::string, int, std::hash<std::string>>);
BENCHMARK_TEMPLATE(BenchFlatMapString, butil::FlatMap<std::string, int, Hasher>);

int main(int argc, char **argv)
{
init(vec);
for (auto i = 0; i < 65536; i++)
// init(vec);
keys.resize(1024);
for (auto i = 0; i < 1024; i++)
{
keys[i] = std::to_string(random_()) + std::to_string(random_());
}

std::fstream fsKeys("keys.txt", std::ios::in);
// std::stringstream ss;
// ss<<fsKeys.rdbuf();
std::string strKey;
while (fsKeys >> strKey)
{
keys[i] = std::to_string(random_())+std::to_string(random_());
vec.emplace_back(std::move(strKey));
}
// keys = vec;
benchmark::Initialize(&argc, argv);
benchmark::RunSpecifiedBenchmarks();
return 0;
Expand Down
Loading

0 comments on commit a2187e2

Please sign in to comment.