66 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++1710 11#include <algorithm>12#include <cstddef>13#include <deque>14#include <iterator>15#include <list>16#include <string>17#include <vector>18 19#include "benchmark/benchmark.h"20#include "../../GenerateInput.h"21 22int main(int argc, char** argv) {23 auto std_rotate_copy = [](auto first, auto middle, auto last, auto out) {24 return std::rotate_copy(first, middle, last, out);25 };26 27 // {std,ranges}::rotate_copy(normal container)28 {29 auto bm = []<class Container>(std::string name, auto rotate_copy) {30 benchmark::RegisterBenchmark(31 name,32 [rotate_copy](auto& st) {33 std::size_t const size = st.range(0);34 using ValueType = typename Container::value_type;35 Container c;36 std::generate_n(std::back_inserter(c), size, [] { return Generate<ValueType>::random(); });37 38 std::vector<ValueType> out(size);39 40 auto middle = std::next(c.begin(), size / 2);41 for ([[maybe_unused]] auto _ : st) {42 benchmark::DoNotOptimize(c);43 benchmark::DoNotOptimize(out);44 auto result = rotate_copy(c.begin(), middle, c.end(), out.begin());45 benchmark::DoNotOptimize(result);46 }47 })48 ->Arg(32)49 ->Arg(50) // non power-of-two50 ->Arg(1024)51 ->Arg(8192);52 };53 bm.operator()<std::vector<int>>("std::rotate_copy(vector<int>)", std_rotate_copy);54 bm.operator()<std::deque<int>>("std::rotate_copy(deque<int>)", std_rotate_copy);55 bm.operator()<std::list<int>>("std::rotate_copy(list<int>)", std_rotate_copy);56 bm.operator()<std::vector<int>>("rng::rotate_copy(vector<int>)", std::ranges::rotate_copy);57 bm.operator()<std::deque<int>>("rng::rotate_copy(deque<int>)", std::ranges::rotate_copy);58 bm.operator()<std::list<int>>("rng::rotate_copy(list<int>)", std::ranges::rotate_copy);59 }60 61 benchmark::Initialize(&argc, argv);62 benchmark::RunSpecifiedBenchmarks();63 benchmark::Shutdown();64 return 0;65}66