Files
clang-p2996/libcxx/test/benchmarks/containers/associative/map.bench.cpp
Louis Dionne 1d319dfe7d [libc++] Implement generic associative container benchmarks (#123663)
This patch implements generic associative container benchmarks for
containers with unique keys. In doing so, it replaces the existing
std::map benchmarks which were based on the cartesian product
infrastructure and were too slow to execute.

These new benchmarks aim to strike a balance between exhaustive coverage
of all operations in the most interesting case, while executing fairly
rapidly (~40s on my machine).

This bumps the requirement for the map benchmarks from C++17 to C++20
because the common header that provides associative container benchmarks
requires support for C++20 concepts.
2025-02-06 16:08:55 -05:00

38 lines
1.3 KiB
C++

//===----------------------------------------------------------------------===//
//
// 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 <map>
#include <string>
#include <utility>
#include "associative_container_benchmarks.h"
#include "../../GenerateInput.h"
#include "benchmark/benchmark.h"
template <class K, class V>
struct support::adapt_operations<std::map<K, V>> {
using ValueType = typename std::map<K, V>::value_type;
using KeyType = typename std::map<K, V>::key_type;
static ValueType value_from_key(KeyType const& k) { return {k, Generate<V>::arbitrary()}; }
static KeyType key_from_value(ValueType const& value) { return value.first; }
using InsertionResult = std::pair<typename std::map<K, V>::iterator, bool>;
static auto get_iterator(InsertionResult const& result) { return result.first; }
};
int main(int argc, char** argv) {
support::associative_container_benchmarks<std::map<int, int>>("std::map<int, int>");
benchmark::Initialize(&argc, argv);
benchmark::RunSpecifiedBenchmarks();
benchmark::Shutdown();
return 0;
}