2 * Copyright 2017 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 // @author Tudor Bosman (tudorb@fb.com)
19 #include <folly/Bits.h>
21 #include <folly/Benchmark.h>
23 using namespace folly;
25 BENCHMARK(nextPowTwoClz, iters) {
26 for (unsigned long i = 0; i < iters; ++i) {
27 auto x = folly::nextPowTwo(iters);
28 folly::doNotOptimizeAway(x);
32 BENCHMARK_DRAW_LINE();
33 BENCHMARK(isPowTwo, iters) {
35 for (unsigned long i = 0; i < iters; ++i) {
36 b = folly::isPowTwo(i);
37 folly::doNotOptimizeAway(b);
41 int main(int argc, char** argv) {
42 gflags::ParseCommandLineFlags(&argc, &argv, true);
43 folly::runBenchmarks();
48 Benchmarks run on dual Xeon X5650's @ 2.67GHz w/hyperthreading enabled
49 (12 physical cores, 12 MB cache, 72 GB RAM)
51 Benchmark Iters Total t t/iter iter/sec
52 ------------------------------------------------------------------------------
53 * nextPowTwoClz 1000000 1.659 ms 1.659 ns 574.8 M