[libcxx-commits] [libcxx] [libc++] Rewrite the set_intersection benchmark without CartesianBenchmarks (PR #214302)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Aug 10 05:08:13 PDT 2026


================
@@ -1,186 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-// UNSUPPORTED: c++03, c++11, c++14, c++17
-
-#include <algorithm>
-#include <cstdlib>
-#include <iterator>
-#include <set>
-#include <vector>
-
-#include "common.h"
-#include "test_iterators.h"
-
-namespace {
-
-// types of containers we'll want to test, covering interesting iterator types
-struct VectorContainer {
-  template <typename... Args>
-  using type = std::vector<Args...>;
-
-  static constexpr const char* Name = "Vector";
-};
-
-struct SetContainer {
-  template <typename... Args>
-  using type = std::set<Args...>;
-
-  static constexpr const char* Name = "Set";
-};
-
-using AllContainerTypes = std::tuple<VectorContainer, SetContainer>;
-
-// set_intersection performance may depend on where matching values lie
-enum class OverlapPosition {
-  None,
-  Front,
-  // performance-wise, matches at the back are identical to ones at the front
-  Interlaced,
-};
-
-struct AllOverlapPositions : EnumValuesAsTuple<AllOverlapPositions, OverlapPosition, 3> {
-  static constexpr const char* Names[] = {"None", "Front", "Interlaced"};
-};
-
-// forward_iterator wrapping which, for each increment, moves the underlying iterator forward Stride elements
-template <typename Wrapped>
-struct StridedFwdIt {
-  Wrapped base_;
-  unsigned stride_;
-
-  using iterator_category = std::forward_iterator_tag;
-  using difference_type   = typename Wrapped::difference_type;
-  using value_type        = typename Wrapped::value_type;
-  using pointer           = typename Wrapped::pointer;
-  using reference         = typename Wrapped::reference;
-
-  StridedFwdIt(Wrapped base, unsigned stride) : base_(base), stride_(stride) { assert(stride_ != 0); }
-
-  StridedFwdIt operator++() {
-    for (unsigned i = 0; i < stride_; ++i)
-      ++base_;
-    return *this;
-  }
-  StridedFwdIt operator++(int) {
-    auto tmp = *this;
-    ++*this;
-    return tmp;
-  }
-  value_type& operator*() { return *base_; }
-  const value_type& operator*() const { return *base_; }
-  value_type& operator->() { return *base_; }
-  const value_type& operator->() const { return *base_; }
-  bool operator==(const StridedFwdIt& o) const { return base_ == o.base_; }
-  bool operator!=(const StridedFwdIt& o) const { return !operator==(o); }
-};
-template <typename Wrapped>
-StridedFwdIt(Wrapped, unsigned) -> StridedFwdIt<Wrapped>;
-
-template <typename T>
-std::vector<T> getVectorOfRandom(size_t N) {
-  std::vector<T> v;
-  fillValues(v, N, Order::Random);
-  sortValues(v, Order::Random);
-  return std::vector<T>(v);
-}
-
-// Realistically, data won't all be nicely contiguous in a container,
-// we'll go through some effort to ensure that it's shuffled through memory
-// this is especially important for containers with non-contiguous element
-// storage, but it will affect even a std::vector, because when you copy a
-// std::vector<std::string> the underlying data storage position for the char
-// arrays of the copy are likely to have high locality
-template <class Container>
-std::pair<Container, Container> genCacheUnfriendlyData(size_t size1, size_t size2, OverlapPosition pos) {
----------------
ldionne wrote:

Much of the complexity in generating data in the new benchmark was aimed to carry forward the coverage that we had from this function in the old benchmark.

https://github.com/llvm/llvm-project/pull/214302


More information about the libcxx-commits mailing list