mirror of
https://github.com/llvm-mirror/libcxx.git
synced 2025-10-22 07:51:39 +08:00

This patch rewrites a few loops in deque and split_buffer to better optimize the codegen. For constructors like `deque<unsigned char> d(500000, 0);` this patch results in a 2x speedup. The patch improves the codegen in roughly three ways: 1. Changes do { ... } while (...) loops into more typical for loops. The optimizer can reason about normal looking loops better. 2. Split the iteration over a range into (A) iteration over the blocks, then (B) iteration within the block. This nested structure helps LLVM lower the inner loop to `memset`. 3. Do fewer things each iteration. Some of these loops were incrementing or changing 4-5 variables every loop (in addition to the construction). Previously most loops would increment the end pointer, the size, and decrement the count of remaining items to construct. Now we only increment a single pointer for most iterations. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@368547 91177308-0d34-0410-b5e6-96231b3b80d8
48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
// -*- 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include <deque>
|
|
|
|
#include "benchmark/benchmark.h"
|
|
|
|
#include "ContainerBenchmarks.hpp"
|
|
#include "GenerateInput.hpp"
|
|
|
|
using namespace ContainerBenchmarks;
|
|
|
|
constexpr std::size_t TestNumInputs = 1024;
|
|
|
|
BENCHMARK_CAPTURE(BM_ConstructSize,
|
|
deque_byte,
|
|
std::deque<unsigned char>{})->Arg(5140480);
|
|
|
|
BENCHMARK_CAPTURE(BM_ConstructSizeValue,
|
|
deque_byte,
|
|
std::deque<unsigned char>{}, 0)->Arg(5140480);
|
|
|
|
BENCHMARK_CAPTURE(BM_ConstructIterIter,
|
|
deque_char,
|
|
std::deque<char>{},
|
|
getRandomIntegerInputs<char>)->Arg(TestNumInputs);
|
|
|
|
BENCHMARK_CAPTURE(BM_ConstructIterIter,
|
|
deque_size_t,
|
|
std::deque<size_t>{},
|
|
getRandomIntegerInputs<size_t>)->Arg(TestNumInputs);
|
|
|
|
BENCHMARK_CAPTURE(BM_ConstructIterIter,
|
|
deque_string,
|
|
std::deque<std::string>{},
|
|
getRandomStringInputs)->Arg(TestNumInputs);
|
|
|
|
|
|
|
|
|
|
BENCHMARK_MAIN();
|