最近在做一些C++相关事情,用的是C++编译成so库,最后引入到android播放器当中的,为了对C++代码进行快速迭代以及做性能测试,准备引入GTEST一个google出品的C++测试库,以及google/benchmark库用来做性能测试
注:其实按照google benchmark在github页面的安装教程来就可以了,这篇文章只是做一个简单的更新,算是一个安装笔记
google benchmark依赖gtest,所以正常安装google benchmark之后,会自动安装gtest
安装
- 在项目的根目录下面执行下面的命令,会在根目录下面生成一个benchmark目录
# Check out the library.
# Benchmark requires Google Test as a dependency. Add the source tree as a subdirectory.
git clone https://github.com/google/benchmark.git
git clone https://github.com/google/googletest.git benchmark/googletest
# Go to the library root directory
cd benchmark
cmake -E make_directory "build"
# cmake -E chdir "build" cmake -DCMAKE_BUILD_TYPE=Release ../
# or, starting with CMake 3.13, use a simpler form:
cmake -DCMAKE_BUILD_TYPE=Release -S . -B "build"
cmake --build "build" --config Release
# check install
# cmake -E chdir "build" ctest --build-config Release
# install global
# sudo cmake --build "build" --config Release --target install
- CMakeList.txt中的引用
cmake_minimum_required(VERSION 3.19)
project(leetcode)
set(CMAKE_CXX_STANDARD 14)
add_subdirectory(benchmark)
# benchmark
set(BENCHMARK_SRC
bench_test.cpp)
add_executable(bench ${
BENCHMARK_SRC})
target_link_libraries(bench benchmark benchmark_main pthread gtest_main)
# 用来引入头文件
# target_include_directories()
# gtest
add_executable(lgtest main_gtest.cpp)
target_link_libraries(lgtest gtest_ma