25 #include <unordered_map> 27 #include <glog/logging.h> 35 using namespace folly;
43 void allocate(
size_t count,
size_t maxSize);
45 void merge(ArenaTester&& other);
49 std::vector<std::pair<uint8_t, Range<uint8_t*>>> areas_;
53 void ArenaTester::allocate(
size_t count,
size_t maxSize) {
56 std::uniform_int_distribution<uint32_t> sizeDist(1, maxSize - 1);
58 areas_.reserve(count);
60 size_t size = sizeDist(rnd);
67 std::random_shuffle(areas_.begin(), areas_.end(), [&rnd](ptrdiff_t n) {
68 return std::uniform_int_distribution<uint32_t>(0, n - 1)(rnd);
71 for (
auto& p : areas_) {
72 std::fill(p.second.begin(), p.second.end(), p.first);
77 for (
auto& p : areas_) {
78 for (
auto v : p.second) {
86 std::lock_guard<std::mutex>
lock(mergeMutex_);
88 other.areas_.begin(), other.areas_.end(), std::back_inserter(areas_));
97 static const size_t requestedBlockSize = 64;
100 size_t blockSize = alignment;
106 while ((p = static_cast<uint8_t*>(arena.
allocate(1))) == prev + alignment) {
108 blockSize += alignment;
111 VLOG(1) <<
"Requested block size: " << requestedBlockSize
112 <<
", actual: " << blockSize;
113 EXPECT_LE(requestedBlockSize, blockSize);
117 static const size_t requestedBlockSize = 64;
121 ArenaTester tester(arena);
122 tester.allocate(100, 100 << 10);
129 static const size_t requestedBlockSize = 64;
131 ArenaTester mainTester(arena);
135 static const size_t numThreads = 20;
136 for (
size_t i = 0;
i < 2;
i++) {
137 std::vector<std::thread>
threads;
138 threads.reserve(numThreads);
139 for (
size_t j = 0; j < numThreads; j++) {
140 threads.emplace_back([&arena, &mainTester]() {
141 ArenaTester tester(arena);
142 tester.allocate(500, 1 << 10);
147 for (
auto&
t : threads) {
156 using Map = std::unordered_map<
163 static const size_t requestedBlockSize = 64;
168 std::equal_to<int>(),
169 ThreadCachedArenaAllocator<std::pair<const int, int>>(arena)};
171 for (
int i = 0;
i < 1000;
i++) {
175 for (
int i = 0;
i < 1000;
i++) {
182 static const int kNumValues = 10000;
185 using Map = std::unordered_map<int, int>;
189 for (
int i = 0;
i < kNumValues;
i++) {
196 using Map = std::unordered_map<
208 std::equal_to<int>(),
209 ThreadCachedArenaAllocator<std::pair<const int, int>>(arena)};
211 for (
int i = 0;
i < kNumValues;
i++) {
220 using Map = std::map<int, int>;
224 for (
int i = 0;
i < kNumValues;
i++) {
245 for (
int i = 0;
i < kNumValues;
i++) {
268 gflags::ParseCommandLineFlags(&argc, &argv,
true);
270 if (!ret && FLAGS_benchmark) {
#define EXPECT_LE(val1, val2)
OutputIt merge(InputIt1 first1, InputIt1 last1, InputIt2 first2, InputIt2 last2, OutputIt d_first, Compare comp)
void * allocate(size_t size)
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
#define EXPECT_EQ(val1, val2)
constexpr detail::Map< Move > move
—— Concurrent Priority Queue Implementation ——
std::unordered_map< int64_t, VecT > Map
std::vector< std::thread::id > threads
constexpr std::size_t max_align_v
constexpr auto size(C const &c) -> decltype(c.size())
auto lock(Synchronized< D, M > &synchronized, Args &&...args)
int main(int argc, char *argv[])
BENCHMARK(fbFollyGlobalBenchmarkBaseline)
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
void merge(unsigned int iters, size_t maxSize, size_t bufSize)
TEST(SequencedExecutor, CPUThreadPoolExecutor)
#define EXPECT_GT(val1, val2)