| 156 | // some percent are inserted in a hashTable. The placement of the |
| 157 | // payload is shuffled so as not to correlate with the probe |
| 158 | // order. Tests the presence/correctness of the hit for each key and |
| 159 | // measures the time for computing hashes/value ids vs the time spent |
| 160 | // probing the table. Covers kArray, kNormalizedKey and kHash hash |
| 161 | // modes. |
| 162 | class HashTableBenchmark : public VectorTestBase { |
| 163 | public: |
| 164 | void makeData(HashTableBenchmarkParams params) { |
| 165 | topTable_.reset(); |
| 166 | batches_.clear(); |
| 167 | rowOfKey_.clear(); |
| 168 | isInTable_.clear(); |
| 169 | params_ = params; |
| 170 | std::vector<TypePtr> dependentTypes; |
| 171 | int32_t sequence = 0; |
| 172 | isInTable_.resize( |
| 173 | bits::nwords(params_.numWays * params_.size), |
| 174 | static_cast<const std::vector< |
| 175 | unsigned long, |
| 176 | std::allocator<unsigned long>>::value_type>(-1)); |
| 177 | if (params_.insertPct != 100) { |
| 178 | // If we probe with all keys but only mean to insert part, we deselect. |
| 179 | folly::Random::DefaultGenerator rng; |
| 180 | rng.seed(1); |
| 181 | for (auto i = 0; i < params_.size * params_.numWays; ++i) { |
| 182 | if (folly::Random::rand32(rng) % 100 > params_.insertPct) { |
| 183 | bits::clearBit(isInTable_.data(), i); |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | int32_t startOffset = 0; |
| 188 | std::vector<std::unique_ptr<BaseHashTable>> otherTables; |
| 189 | for (auto way = 0; way < params_.numWays; ++way) { |
| 190 | std::vector<RowVectorPtr> batches; |
| 191 | std::vector<std::unique_ptr<VectorHasher>> keyHashers; |
| 192 | for (auto channel = 0; channel < params_.numKeys; ++channel) { |
| 193 | keyHashers.emplace_back(std::make_unique<VectorHasher>( |
| 194 | params_.buildType->childAt(channel), channel)); |
| 195 | } |
| 196 | auto table = HashTable<true>::createForJoin( |
| 197 | std::move(keyHashers), |
| 198 | dependentTypes, |
| 199 | true, |
| 200 | false, |
| 201 | BaseHashTable::HashMode::kArray, |
| 202 | 1'000, |
| 203 | pool_.get(), |
| 204 | params.enableJitRowEqVectors); |
| 205 | |
| 206 | makeRows(params_.size, 1, sequence, params_.buildType, batches); |
| 207 | copyVectorsToTable(batches, startOffset, table.get()); |
| 208 | sequence += params_.size; |
| 209 | if (!topTable_) { |
| 210 | topTable_ = std::move(table); |
| 211 | } else { |
| 212 | otherTables.push_back(std::move(table)); |
| 213 | } |
| 214 | batches_.insert(batches_.end(), batches.begin(), batches.end()); |
| 215 | startOffset += params_.size; |
no test coverage detected