Facebook Open-source Library (Folly)

a library of C++14 components designed with practicality and efficiency in mind. - github

see also

Benchmark Tool

Benchmark timings are not a regular random variable that fluctuates around an average.

  • doNotOptimizeAway( yourvar) - prevents compiler optimizations that may interfere with benchmarking

BENCHMARK(insertVectorBegin, iters)

The first is the name of the benchmark.
The second argument may be missing, or could be a symbolic counter. The counter dictates how many internal iteration the benchmark does.

BENCHMARK(insertVectorBegin, iters) {
    vector<int> v;
    FOR_EACH_RANGE (i, 0, iters) {
      v.insert(v.begin(), 42);
    }
  }

BENCHMARK_COUNTERS(name, counters, ...)

Allow users to record customized counter during benchmarking, there will be one extra column showing in the output result for each counter

BENCHMARK_PARAM(pushBack, 0)
BENCHMARK_PARAM(pushBack, 1000)
BENCHMARK_PARAM(pushBack, 1000000)

Like BENCHMARK_PARAM(), but allows a custom name to be specified for each parameter, rather than using the parameter value.

Useful when the parameter value is not a valid token for string pasting, of when you want to specify multiple parameter arguments.

BENCHMARK_NAMED_PARAM(addValue, 0_to_100, 1, 0, 100)
BENCHMARK_NAMED_PARAM(addValue, 0_to_1000, 10, 0, 1000)
BENCHMARK_NAMED_PARAM(addValue, 5k_to_20k, 250, 5000, 20000)

BENCHMARK_SUSPEND

Allows execution of code that doesn’t count torward the benchmark’s time budget.

BENCHMARK_START_GROUP(insertVectorBegin, n) {
    vector<int> v;
    BENCHMARK_SUSPEND {
      v.reserve(n);
    }
    FOR_EACH_RANGE (i, 0, n) {
      v.insert(v.begin(), 42);
    }
  }

Installation

Not trivial to get dependancies rigth…

g++  example.cc -lfollybenchmark -lfolly -lglog -lgflags -pthread -lm -lpthread -ldl -ldouble-conversion -lboost_regex -lssl -lcrypto -liberty

prefer to use Meson + CMake subproject + install FMT

FMT

Folly relies on fmt which needs to be installed from source.

mkdir build          # Create a directory to hold the build output.
cd build
cmake ..  # Generate native build scripts.

Manual setup

sudo apt-get install \
    g++ \
    cmake \
    libboost-all-dev \
    libevent-dev \
    libdouble-conversion-dev \
    libgoogle-glog-dev \
    libgflags-dev \
    libiberty-dev \
    liblz4-dev \
    liblzma-dev \
    libsnappy-dev \
    make \
    zlib1g-dev \
    binutils-dev \
    libjemalloc-dev \
    libssl-dev \
    pkg-config \
    libunwind-dev
Written on June 20, 2021, Last update on November 11, 2021
lib c++ benchmarking fastware