proxygen
BitsBenchmark.cpp File Reference
#include <atomic>
#include <memory>
#include <random>
#include <glog/logging.h>
#include <folly/Benchmark.h>
#include <folly/experimental/Bits.h>

Go to the source code of this file.

Functions

std::vector< uint8_tbuffer (kBufferSize+16)
 
template<class T >
void benchmarkSet (size_t n, T)
 
 BENCHMARK_DRAW_LINE ()
 
std::atomic< int64_tsum (0)
 
template<class T >
void benchmarkGet (size_t n, T x)
 
int main (int argc, char *argv[])
 

Variables

std::random_device rd
 
const size_t kBufferSize = 1 << 10
 

Function Documentation

BENCHMARK_DRAW_LINE ( )

Referenced by benchmarkSet().

template<class T >
void benchmarkGet ( size_t  n,
T  x 
)

Definition at line 80 of file BitsBenchmark.cpp.

References BENCHMARK_NAMED_PARAM, BENCHMARK_RELATIVE_NAMED_PARAM, benchmarkSet(), buffer(), folly::doNotOptimizeAway(), folly::Bits< T, Traits >::get(), i, int16_t, int32_t, int64_t, kBufferSize, s, folly::size(), T, folly::detail::distributed_mutex::time(), uint16_t, uint32_t, and uint64_t.

80  {
81  size_t size = sizeof(T) * 6.9; // use 6.9 bits/byte
82  for (size_t i = 0; i < n; ++i) {
83  size_t bit = (i * 2973) % (kBufferSize * 8);
84  size_t drop = i % size;
86  reinterpret_cast<T*>(buffer.data()), bit, size - drop);
87  }
89 }
Definition: InvokeTest.cpp:58
std::vector< uint8_t > buffer(kBufferSize+16)
#define T(v)
Definition: http_parser.c:233
static UnderlyingType get(const T *p, size_t bitStart, size_t count)
Definition: Bits.h:285
const size_t kBufferSize
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
template<class T >
void benchmarkSet ( size_t  n,
T   
)

Definition at line 32 of file BitsBenchmark.cpp.

References BENCHMARK_DRAW_LINE(), BENCHMARK_NAMED_PARAM, BENCHMARK_RELATIVE_NAMED_PARAM, BENCHMARK_SUSPEND, buffer(), folly::doNotOptimizeAway(), folly::findLastSet(), i, int16_t, int32_t, int64_t, k, kBufferSize, max, min, rd, folly::Bits< T, Traits >::set(), folly::size(), sum(), T, uint16_t, uint32_t, uint64_t, value, and values().

Referenced by benchmarkGet().

32  {
33  size_t size = sizeof(T) * 6.9; // use 6.9 bits/byte
34  const size_t k = 16;
35  T values[k];
37  std::mt19937 gen(rd());
38  T max, min;
40  max = (T(1) << (size - 1)) - 1;
41  min = -(T(1) << (size - 1));
42  } else {
43  max = (T(1) << size) - 1;
44  min = 0;
45  }
46  CHECK_LE(folly::findLastSet(max), size);
47  CHECK_LE(folly::findLastSet(-min), size);
48  std::uniform_int_distribution<T> dis(min, max);
49  for (size_t i = 0; i < k; ++i) {
50  values[i] = dis(gen);
51  }
52  }
53 
54  for (size_t i = 0; i < n; ++i) {
55  size_t bit = (i * 2973) % (kBufferSize * 8);
56  size_t drop = i % size;
58  reinterpret_cast<T*>(buffer.data()),
59  bit,
60  size - drop,
61  values[i % k] >> drop);
62  }
63 
65  folly::Bits<T>::test(reinterpret_cast<T*>(buffer.data()), 512));
66 }
std::vector< uint8_t > buffer(kBufferSize+16)
#define T(v)
Definition: http_parser.c:233
static void set(T *p, size_t bit)
Definition: Bits.h:220
LogLevel max
Definition: LogLevel.cpp:31
#define BENCHMARK_SUSPEND
Definition: Benchmark.h:576
const size_t kBufferSize
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
LogLevel min
Definition: LogLevel.cpp:30
constexpr unsigned int findLastSet(T const v)
Definition: Bits.h:105
static const char *const value
Definition: Conv.cpp:50
std::random_device rd
KeyT k
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
std::vector< int > values(1'000)
std::vector<uint8_t> buffer ( kBufferSize 16)

Referenced by folly::io::addOutputBuffer(), ReadCallback::Buffer::allocate(), folly::ReadCallback::Buffer::allocate(), proxygen::QPACKEncoder::allowVulnerable(), append(), folly::gen::detail::Window::Generator< Value, Source, StorageType >::apply(), BENCHMARK_RELATIVE(), benchmarkGet(), benchmarkSet(), folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::Data::buffer(), folly::io::test::compressSome(), proxygen::StructuredHeadersStandardTest::decode32Block(), folly::io::StreamCodec::doCompress(), folly::io::StreamCodec::doUncompress(), estimateQuantile(), folly::estimateSpaceNeeded(), folly::CustomLogFormatter::formatMessage(), folly::GlogStyleFormatter::formatMessage(), ReadCallback::Buffer::free(), folly::ReadCallback::Buffer::free(), folly::fibers::Fiber::LocalData::freeHeapBuffer(), proxygen::HTTPArchive::fromFile(), proxygen::HTTPArchive::fromPublicFile(), folly::fibers::Fiber::LocalData::get(), folly::getFileAsBuf(), testing::internal::GetThreadCount(), folly::AsyncServerSocket::handlerReady(), folly::IOBuf::headroom(), main(), merge(), mergeDigests(), read_all(), testing::internal::ReadEntireFile(), proxygen::readFileToIOBuf(), readThread(), ReadCallback::Buffer::reset(), folly::ReadCallback::Buffer::reset(), folly::IPAddressV6::str(), stringPrintfOutputSize(), StringUnsplit_Gen(), TEST(), folly::io::test::TEST(), TEST_F(), folly::io::test::TEST_P(), testConcatenation(), testFreeFn(), folly::toAppend(), u2aAppendClassicBM(), u2aAppendFollyBM(), folly::io::test::uncompressSome(), folly::detail::writeIntegerString(), folly::AsyncFileWriter::writeMessage(), and folly::LogWriter::~LogWriter().

int main ( int  argc,
char *  argv[] 
)

Definition at line 118 of file BitsBenchmark.cpp.

References folly::runBenchmarks(), and sum().

118  {
119  gflags::ParseCommandLineFlags(&argc, &argv, true);
121  return sum.load();
122 }
std::atomic< int64_t > sum(0)
void runBenchmarks()
Definition: Benchmark.cpp:456
char ** argv

Variable Documentation

const size_t kBufferSize = 1 << 10
std::random_device rd

Definition at line 26 of file BitsBenchmark.cpp.

Referenced by BENCHMARK(), benchmarkSet(), and TEST().