其他分享
首页 > 其他分享> > folly库之Benchmark.h

folly库之Benchmark.h

作者:互联网

什么是benchmark与baseline?  https://www.zhihu.com/question/22529709

folly/Benchmark.h提供了用于编写和执行基准测试的简单框架。当前,该框架仅针对单线程测试。

简单的使用方式:

#include <folly/Benchmark.h>
#include <folly/container/Foreach.h>
#include <vector>
using namespace std;
using namespace folly;
BENCHMARK(insertFrontVectorX) {
    // Let's insert 100 elements at the front of a vector
    vector<int> v;
    FOR_EACH_RANGE (i, 0, 100) {
        v.insert(v.begin(), i);
    }
}
BENCHMARK_RELATIVE(insertBackVector_0) {
    // Let's insert 100 elements at the back of a vector
    vector<int> v;
    FOR_EACH_RANGE (i, 0, 100) {
        v.insert(v.end(), i);
    }
}
BENCHMARK_RELATIVE(insertBackVector_1) {
    // Let's insert 100 elements at the back of a vector
    vector<int> v;
    FOR_EACH_RANGE (i, 0, 100) {
        v.insert(v.end(), i);
    }
}
int main() {
    runBenchmarks();
}

输出:

相关解析:https://github.com/facebook/folly/blob/master/folly/docs/Benchmark.md

 

标签:insert,folly,Benchmark,vector,100,include
来源: https://www.cnblogs.com/iuyy/p/14162655.html