遇见YY

导航

 

什么是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

 
posted on 2020-12-20 09:51  一骑红尘妃子笑!  阅读(413)  评论(0编辑  收藏  举报