Skip to content

Commit 3bf191e

Browse files
committed
split benchmark implementation in multiple files
1 parent d143aef commit 3bf191e

11 files changed

+537
-356
lines changed

CMakeLists.txt

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,63 @@
11
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
22

3-
project(SortingNetworkCpp)
3+
project(sorting_network_cpp)
44

55
option(BUILD_BENCHMARK "Build the benchmark" ON)
66
option(BUILD_TESTS "Build the tests" OFF)
77

88
include(cmake/Conan.cmake)
99
run_conan()
1010

11-
set(SN_BENCHMARK_EXECUTABLE_NAME "sorting_network_cpp_benchmark")
12-
set(SN_TESTS_EXECUTABLE_NAME "sorting_network_cpp_tests")
13-
1411
set(CMAKE_CXX_STANDARD 17)
1512
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1613

1714
add_library(project_options INTERFACE)
1815
target_compile_features(project_options INTERFACE cxx_std_17)
1916

2017
if (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
21-
set(CMAKE_CXX_FLAGS_RELEASE "/W3 /O2 /fp:fast")
22-
add_compile_options("-bigobj")
18+
target_compile_options(project_options INTERFACE /W3 /O2 /fp:fast)
19+
target_link_options(project_options INTERFACE /OPT:REF /GL)
2320
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
24-
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -ffast-math")
21+
target_compile_options(project_options INTERFACE -O3 -ffast-math)
2522
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
26-
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -ffast-math")
23+
target_compile_options(project_options INTERFACE -O3 -ffast-math)
2724
endif()
2825

29-
include_directories("include")
26+
add_library(sorting_network_cpp_lib INTERFACE)
27+
target_include_directories(sorting_network_cpp_lib INTERFACE "include")
3028

3129
add_library(metal INTERFACE)
3230
target_include_directories(metal INTERFACE "extern/metal/include")
3331

3432
if (BUILD_BENCHMARK)
35-
add_executable(${SN_BENCHMARK_EXECUTABLE_NAME} "src/benchmark.cpp")
36-
target_link_libraries(${SN_BENCHMARK_EXECUTABLE_NAME} PRIVATE project_options)
33+
set(SN_BENCHMARK_EXECUTABLE_NAME ${PROJECT_NAME}_benchmark)
34+
35+
add_executable(${SN_BENCHMARK_EXECUTABLE_NAME}
36+
"src/benchmark_main.cpp"
37+
"src/benchmark_int16.cpp"
38+
"src/benchmark_int32.cpp"
39+
"src/benchmark_uint32.cpp"
40+
"src/benchmark_int64.cpp"
41+
"src/benchmark_float.cpp"
42+
"src/benchmark_double.cpp"
43+
"src/benchmark_vec2i.cpp"
44+
)
45+
target_link_libraries(${SN_BENCHMARK_EXECUTABLE_NAME} PRIVATE project_options sorting_network_cpp_lib)
3746
endif()
3847

3948
if(BUILD_TESTS)
40-
find_package(GTest REQUIRED)
41-
include(GoogleTest)
42-
43-
add_executable(${SN_TESTS_EXECUTABLE_NAME}
44-
"test/test_base.h"
45-
"test/test_batcher_odd_even_merge_sort.cpp"
46-
"test/test_bitonic_merge_sort.cpp"
47-
"test/test_bose_nelson_sort.cpp"
48-
"test/test_bubble_sort.cpp"
49-
"test/test_insertion_sort.cpp"
50-
"test/test_size_optimized_sort.cpp"
51-
)
52-
target_link_libraries(${SN_TESTS_EXECUTABLE_NAME} GTest::gtest GTest::gtest_main metal project_options)
49+
set(SN_TESTS_EXECUTABLE_NAME ${PROJECT_NAME}_tests)
50+
find_package(GTest REQUIRED)
51+
include(GoogleTest)
52+
53+
add_executable(${SN_TESTS_EXECUTABLE_NAME}
54+
"test/test_base.h"
55+
"test/test_batcher_odd_even_merge_sort.cpp"
56+
"test/test_bitonic_merge_sort.cpp"
57+
"test/test_bose_nelson_sort.cpp"
58+
"test/test_bubble_sort.cpp"
59+
"test/test_insertion_sort.cpp"
60+
"test/test_size_optimized_sort.cpp"
61+
)
62+
target_link_libraries(${SN_TESTS_EXECUTABLE_NAME} GTest::gtest GTest::gtest_main metal project_options sorting_network_cpp_lib)
5363
endif()

src/benchmark.cpp

Lines changed: 0 additions & 142 deletions
This file was deleted.

src/benchmark_double.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// This file is part of the sorting_network_cpp (https://github.com/quxflux/sorting_network_cpp).
2+
// Copyright (c) 2022 Lukas Riebel.
3+
//
4+
// sorting_network_cpp is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// sorting_network_cpp is distributed in the hope that it will be useful, but
10+
// WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
// General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
#include "util.h"
18+
19+
namespace quxflux
20+
{
21+
IMPL_BENCHMARK(double);
22+
}

src/benchmark_float.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// This file is part of the sorting_network_cpp (https://github.com/quxflux/sorting_network_cpp).
2+
// Copyright (c) 2022 Lukas Riebel.
3+
//
4+
// sorting_network_cpp is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// sorting_network_cpp is distributed in the hope that it will be useful, but
10+
// WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
// General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
#include "util.h"
18+
19+
namespace quxflux
20+
{
21+
IMPL_BENCHMARK(float);
22+
}

src/benchmark_int16.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// This file is part of the sorting_network_cpp (https://github.com/quxflux/sorting_network_cpp).
2+
// Copyright (c) 2022 Lukas Riebel.
3+
//
4+
// sorting_network_cpp is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// sorting_network_cpp is distributed in the hope that it will be useful, but
10+
// WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
// General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
#include "util.h"
18+
19+
namespace quxflux
20+
{
21+
IMPL_BENCHMARK(int16_t);
22+
}

src/benchmark_int32.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// This file is part of the sorting_network_cpp (https://github.com/quxflux/sorting_network_cpp).
2+
// Copyright (c) 2022 Lukas Riebel.
3+
//
4+
// sorting_network_cpp is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// sorting_network_cpp is distributed in the hope that it will be useful, but
10+
// WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
// General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
#include "util.h"
18+
19+
namespace quxflux
20+
{
21+
IMPL_BENCHMARK(int32_t);
22+
}

src/benchmark_int64.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// This file is part of the sorting_network_cpp (https://github.com/quxflux/sorting_network_cpp).
2+
// Copyright (c) 2022 Lukas Riebel.
3+
//
4+
// sorting_network_cpp is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// sorting_network_cpp is distributed in the hope that it will be useful, but
10+
// WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
// General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
#include "util.h"
18+
19+
namespace quxflux
20+
{
21+
IMPL_BENCHMARK(int64_t);
22+
}

0 commit comments

Comments
 (0)