proxygen
BitsBenchmark.cpp File Reference
#include <algorithm>
#include <vector>
#include <folly/CppAttributes.h>
#include <folly/Random.h>
#include <folly/lang/Assume.h>
#include <folly/lang/Bits.h>
#include <folly/Benchmark.h>

Go to the source code of this file.

Functions

 BENCHMARK (nextPowTwoClz, iters)
 
 BENCHMARK_DRAW_LINE ()
 
 BENCHMARK (isPowTwo, iters)
 
 BENCHMARK (reverse, iters)
 
 BENCHMARK (PartialLoadUnaligned, iters)
 
 BENCHMARK (PartialLoadUnalignedMemcpy, iters)
 
 BENCHMARK (PartialLoadUnalignedSwitch, iters)
 
int main (int argc, char **argv)
 

Function Documentation

BENCHMARK ( nextPowTwoClz  ,
iters   
)

Definition at line 31 of file BitsBenchmark.cpp.

References folly::BENCHMARK_DRAW_LINE(), folly::doNotOptimizeAway(), i, and folly::nextPowTwo().

31  {
32  for (unsigned long i = 0; i < iters; ++i) {
33  auto x = folly::nextPowTwo(i);
35  }
36 }
Definition: InvokeTest.cpp:58
constexpr T nextPowTwo(T const v)
Definition: Bits.h:149
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( isPowTwo  ,
iters   
)

Definition at line 39 of file BitsBenchmark.cpp.

References b, folly::BENCHMARK_DRAW_LINE(), folly::doNotOptimizeAway(), i, and folly::isPowTwo().

39  {
40  bool b;
41  for (unsigned long i = 0; i < iters; ++i) {
42  b = folly::isPowTwo(i);
44  }
45 }
char b
constexpr bool isPowTwo(T const v)
Definition: Bits.h:161
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( reverse  ,
iters   
)

Definition at line 48 of file BitsBenchmark.cpp.

References folly::assume(), b, folly::BENCHMARK_DRAW_LINE(), BENCHMARK_SUSPEND, folly::bitReverse(), folly::doNotOptimizeAway(), f, FOLLY_FALLTHROUGH, i, folly::Random::rand32(), and uint64_t.

48  {
49  uint64_t b = 0;
50  for (unsigned long i = 0; i < iters; ++i) {
51  b = folly::bitReverse(i + b);
53  }
54 }
char b
T bitReverse(T n)
Definition: Bits.h:369
auto doNotOptimizeAway(const T &datum) -> typename std::enable_if< !detail::DoNotOptimizeAwayNeedsIndirect< T >::value >::type
Definition: Benchmark.h:258
BENCHMARK ( PartialLoadUnaligned  ,
iters   
)

Definition at line 126 of file BitsBenchmark.cpp.

126  {
127  testPartialLoadUnaligned(folly::partialLoadUnaligned<uint64_t>, iters);
128 }
BENCHMARK ( PartialLoadUnalignedMemcpy  ,
iters   
)

Definition at line 130 of file BitsBenchmark.cpp.

References folly::assume(), and uint64_t.

130  {
131  testPartialLoadUnaligned(
132  [](const char* p, size_t l) {
133  folly::assume(l < 8);
134 
135  uint64_t ret;
136  memcpy(&ret, p, l);
137  return ret;
138  },
139  iters);
140 }
FOLLY_ALWAYS_INLINE void assume(bool cond)
Definition: Assume.h:41
BENCHMARK ( PartialLoadUnalignedSwitch  ,
iters   
)

Definition at line 142 of file BitsBenchmark.cpp.

142  {
143  testPartialLoadUnaligned(partialLoadUnalignedSwitch, iters);
144 }
BENCHMARK_DRAW_LINE ( )
int main ( int  argc,
char **  argv 
)

Definition at line 146 of file BitsBenchmark.cpp.

References folly::runBenchmarks().

146  {
147  gflags::ParseCommandLineFlags(&argc, &argv, true);
149  return 0;
150 }
void runBenchmarks()
Definition: Benchmark.cpp:456
char ** argv