Skip to content

Commit

Permalink
fetch content gtest
Browse files Browse the repository at this point in the history
  • Loading branch information
gen740 committed Dec 13, 2023
1 parent 7f5977f commit fb28175
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
12 changes: 9 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,26 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_LIST_DIR})
set(CMAKE_CXX_FLAGS_RELEASE "")
set(CMAKE_CXX_FLAGS_DEBUG "")

find_package(GTest REQUIRED)
include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
FetchContent_MakeAvailable(googletest)

file(GLOB ARGO_TEST_SOURCES ${CMAKE_CURRENT_LIST_DIR}/tests/*.cc)

############################### DEBUG TARGET ##############################
add_executable(test-argo-debug ${ARGO_TEST_SOURCES})
target_link_libraries(test-argo-debug GTest::GTest GTest::Main GTest::gmock
target_link_libraries(test-argo-debug GTest::gtest GTest::gtest_main GTest::gmock
Argo)
set_target_properties(test-argo-debug PROPERTIES CXX_STANDARD 23)
target_compile_options(test-argo-debug PRIVATE -Wno-writable-strings
-DDEBUG_BUILD -O1 -g)

############################### RELEASE TARGET ############################
add_executable(test-argo-release ${ARGO_TEST_SOURCES})
target_link_libraries(test-argo-release GTest::GTest GTest::Main
target_link_libraries(test-argo-release GTest::gtest GTest::gtest_main
GTest::gmock Argo)
set_target_properties(test-argo-release PROPERTIES CXX_STANDARD 23)
target_compile_options(test-argo-release PRIVATE -Wno-writable-strings -O3)
Expand Down
31 changes: 16 additions & 15 deletions benchmarks/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ std::tuple<int, char**> createArgcArgv(Args... args) {
return std::make_tuple(static_cast<int>(N), array);
}

auto [argc, argv] = createArgcArgv( //
"./main", //
"--arg1", "1", "2", "3", "4", "5", "6", "7", "8", //
"--arg2", "42.23", //
"--arg3", //
"--arg4", "Hello,World", //
"-bc", "-d", "3.14", // 17
"-efgijklmn", //
"--arg18", //
"0", "1", "2", "3", "4", //
"--arg19", //
"0.1", "0.2", "0.3" //
auto [argc, argv] = createArgcArgv( //
"./main", //
"--arg1", "1", "2", "3", //
"--arg2", "42.23", //
"--arg3", //
"--arg4", "Hello,World", //
"-bc", "-d", "3.14", // 17
"-efgijklmn", //
"--arg18", //
"0", "1", "2", "3", "4", //
"--arg19", //
"0.1", "0.2", "0.3" //
);

using Argo::nargs;
Expand All @@ -39,7 +39,7 @@ using Argo::Parser;
static void ArgoParser(benchmark::State& state) {
for (auto _ : state) {
auto parser = Parser<1>() //
.addArg<"arg1", int, nargs(8)>()
.addArg<"arg1", int, nargs(3)>()
.addArg<"arg2", float>()
.addFlag<"arg3">()
.addArg<"arg4", std::string, nargs(1)>()
Expand Down Expand Up @@ -69,8 +69,9 @@ static void CLI11Parser(benchmark::State& state) {
for (auto _ : state) {
auto app = CLI::App{"App description"};

std::array<int, 8> arg1;
std::array<int, 3> arg1;
app.add_option("--arg1", arg1);

float arg2;
app.add_option("--arg2", arg2);
app.add_flag("--arg3");
Expand Down Expand Up @@ -114,7 +115,7 @@ BENCHMARK(CLI11Parser);
static void argparseParser(benchmark::State& state) {
for (auto _ : state) {
auto program = argparse::ArgumentParser("program_name");
program.add_argument("--arg1").nargs(8).scan<'d', int>();
program.add_argument("--arg1").nargs(3).scan<'d', int>();
program.add_argument("--arg2").scan<'g', double>();
program.add_argument("--arg3").default_value(false);
program.add_argument("--arg4").nargs(1);
Expand Down

0 comments on commit fb28175

Please sign in to comment.