Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] Improve naming of test runs #4

Merged
merged 5 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .github/workflows/build-and-run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ concurrency:
cancel-in-progress: true
jobs:
test:
name: ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ windows-latest, macos-latest, ubuntu-latest ]
build_type: [Debug]
build_type: [Debug, Release]
cxx_standard: [14, 17, 20, 23]
exclude:
- os: macos-latest
cxx_standard: 23
env:
PREFIX: ${{ github.workspace }}/_local
steps:
Expand Down
21 changes: 8 additions & 13 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@

find_package(benchmark REQUIRED)

set(BENCH_SOURCE_FILES
dummy_bench.cpp
add_executable(ubench
unstable_remove_bench.cpp
)
target_include_directories(ubench PRIVATE ${SG14_INCLUDE_DIRECTORY})
target_link_libraries(ubench PRIVATE benchmark::benchmark_main)

set(BENCH_NAME ubench)
add_executable(${BENCH_NAME} ${BENCH_SOURCE_FILES})
include_directories(${BENCHMARK_INCLUDE_DIRS} ${SG14_INCLUDE_DIRECTORY})
target_link_libraries(${BENCH_NAME} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(${BENCH_NAME} benchmark::benchmark_main)
## Ad-hoc compiler options ##

# Compile options
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
target_compile_options(${BENCH_NAME} PRIVATE -Wall -Wextra -Werror)
set_property(TARGET ubench APPEND PROPERTY COMPILE_OPTIONS "-Wall;-Wextra;-Werror")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
target_compile_options(${BENCH_NAME} PRIVATE -Wall -Wextra -Werror)
set_property(TARGET ubench APPEND PROPERTY COMPILE_OPTIONS "-Wall;-Wextra;-Werror")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${BENCH_NAME})
target_compile_options(${BENCH_NAME} PRIVATE /Zc:__cplusplus /permissive- /W4 /WX)
add_definitions(-DNOMINMAX -D_SCL_SECURE_NO_WARNINGS)
set_property(TARGET ubench APPEND PROPERTY COMPILE_OPTIONS "-W4;-WX;-DNOMINMAX;-D_SCL_SECURE_NO_WARNINGS")
endif()
80 changes: 80 additions & 0 deletions benchmarks/unstable_remove_bench.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@

#include <benchmark/benchmark.h>
#include <sg14/algorithm_ext.h>
#include <random>
#include <vector>

static std::vector<std::array<int, 16>> get_sample_data()
{
std::mt19937 g;
auto v = std::vector<std::array<int, 16>>(30'000);
for (auto& arr : v) {
std::generate_n(arr.data(), arr.size(), std::ref(g));
}
return v;
}

static auto isOdd = [](const std::array<int, 16>& t) { return (t[0] & 1) != 0; };
static auto isEven = [](const std::array<int, 16>& t) { return (t[0] & 1) == 0; };

static void UnstableRemoveIf(benchmark::State& state)
{
auto orig = get_sample_data();
auto v1 = orig;
auto v2 = orig;

for (auto _ : state) {
auto it1 = sg14::unstable_remove_if(v1.begin(), v1.end(), isOdd);
auto it2 = sg14::unstable_remove_if(v2.begin(), v2.end(), isEven);
state.PauseTiming();
benchmark::DoNotOptimize(it1);
benchmark::DoNotOptimize(it2);
benchmark::ClobberMemory();
std::copy(orig.begin(), orig.end(), v1.begin());
std::copy(orig.begin(), orig.end(), v2.begin());
state.ResumeTiming();
}
}
BENCHMARK(UnstableRemoveIf);

static void StdPartition(benchmark::State& state)
{
auto orig = get_sample_data();
auto v1 = orig;
auto v2 = orig;

for (auto _ : state) {
auto it1 = std::partition(v1.begin(), v1.end(), isOdd);
auto it2 = std::partition(v2.begin(), v2.end(), isEven);
state.PauseTiming();
benchmark::DoNotOptimize(it1);
benchmark::DoNotOptimize(it2);
benchmark::ClobberMemory();
std::copy(orig.begin(), orig.end(), v1.begin());
std::copy(orig.begin(), orig.end(), v2.begin());
state.ResumeTiming();
}
}
BENCHMARK(StdPartition);

static void StdRemoveIf(benchmark::State& state)
{
auto orig = get_sample_data();
auto v1 = orig;
auto v2 = orig;

for (auto _ : state) {
auto it1 = std::remove_if(v1.begin(), v1.end(), isOdd);
auto it2 = std::remove_if(v2.begin(), v2.end(), isEven);
state.PauseTiming();
benchmark::DoNotOptimize(it1);
benchmark::DoNotOptimize(it2);
benchmark::ClobberMemory();
std::copy(orig.begin(), orig.end(), v1.begin());
std::copy(orig.begin(), orig.end(), v2.begin());
state.ResumeTiming();
}
}
BENCHMARK(StdRemoveIf);

BENCHMARK_MAIN();
24 changes: 13 additions & 11 deletions include/sg14/inplace_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct SG14_INPLACE_VECTOR_TRIVIALLY_RELOCATABLE_IF(std::is_trivially_relocatabl
if constexpr (std::is_trivially_copy_constructible_v<T>) {
std::memmove(this, std::addressof(rhs), sizeof(ipvbase));
} else {
std::uninitialized_copy_n(rhs.data_, rhs.data_ + rhs.size_, data_);
std::uninitialized_copy_n(rhs.data_, rhs.size_, data_);
size_ = rhs.size_;
}
}
Expand Down Expand Up @@ -258,7 +258,7 @@ class inplace_vector : ipvbase_assignable<T>, ipvbase_t<T, N> {
(*this)[i] = value;
}
for (size_t i = m; i < n; ++i) {
unchecked_push_back(value);
unchecked_emplace_back(value);
}
}
}
Expand Down Expand Up @@ -325,7 +325,8 @@ class inplace_vector : ipvbase_assignable<T>, ipvbase_t<T, N> {

constexpr void resize(size_type n) {
if (n < size_) {
erase(begin() + n, end());
std::destroy(data() + n, data() + size_);
set_size_(n);
} else if (n > N) {
SG14_INPLACE_VECTOR_THROW(std::bad_alloc());
} else {
Expand All @@ -337,12 +338,13 @@ class inplace_vector : ipvbase_assignable<T>, ipvbase_t<T, N> {

constexpr void resize(size_type n, const value_type& value) {
if (n < size_) {
erase(begin() + n, end());
std::destroy(data() + n, data() + size_);
set_size_(n);
} else if (n > N) {
SG14_INPLACE_VECTOR_THROW(std::bad_alloc());
} else {
for (size_t i = n - size_; i != 0; --i) {
unchecked_push_back(value);
unchecked_emplace_back(value);
}
}
}
Expand Down Expand Up @@ -569,19 +571,19 @@ class inplace_vector : ipvbase_assignable<T>, ipvbase_t<T, N> {
iterator erase(const_iterator first, const_iterator last) {
auto ifirst = iterator(first);
auto ilast = iterator(last);
if (ifirst != ilast) {
auto n = ilast - ifirst;
if (n != 0) {
auto oldend = end();
#if defined(__cpp_lib_trivially_relocatable)
if constexpr (std::is_trivially_relocatable_v<value_type>) {
std::destroy(ifirst, ilast);
auto newend = std::uninitialized_relocate(ilast, oldend, ifirst);
set_size_(size_ - (oldend - newend));
std::uninitialized_relocate(ilast, oldend, ifirst);
set_size_(size_ - n);
return ifirst;
}
#endif // __cpp_lib_trivially_relocatable
auto newend = std::move(ilast, oldend, ifirst);
std::destroy(newend, oldend);
set_size_(size_ - (oldend - newend));
std::destroy(std::move(ilast, oldend, ifirst), oldend);
set_size_(size_ - n);
}
return ifirst;
}
Expand Down
1 change: 0 additions & 1 deletion test/flat_map_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <gtest/gtest.h>

#include <cassert>
#include <deque>
#include <functional>
#include <list>
Expand Down
1 change: 0 additions & 1 deletion test/flat_set_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <gtest/gtest.h>

#include <algorithm>
#include <cassert>
#include <deque>
#include <functional>
#if __has_include(<memory_resource>)
Expand Down
1 change: 0 additions & 1 deletion test/inplace_function_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <gtest/gtest.h>

#include <cassert>
#include <memory>
#include <string>
#include <type_traits>
Expand Down
26 changes: 26 additions & 0 deletions test/inplace_vector_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,32 @@ TEST(inplace_vector, ConstructorsThrow)
}
}

TEST(inplace_vector, Copying)
{
{
using V = sg14::inplace_vector<int, 5>;
V source = {1,2,3};
V dest = source;
EXPECT_EQ(dest, (V{1,2,3}));
dest = {4,5};
EXPECT_EQ(dest, (V{4,5}));
dest = source;
EXPECT_EQ(dest, (V{1,2,3}));
EXPECT_EQ(source, (V{1,2,3}));
}
{
using V = sg14::inplace_vector<std::string, 5>;
V source = {"1", "2", "3"};
V dest = source;
EXPECT_EQ(dest, Seq("1", "2", "3"));
dest = {"4", "5"};
EXPECT_EQ(dest, Seq("4", "5"));
dest = source;
EXPECT_EQ(dest, Seq("1", "2", "3"));
EXPECT_EQ(source, Seq("1", "2", "3"));
}
}

TEST(inplace_vector, TransfersOfOwnership)
{
{
Expand Down
10 changes: 5 additions & 5 deletions test/slot_map_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <gtest/gtest.h>

#include <algorithm>
#include <cassert>
#include <cinttypes>
#include <deque>
#include <forward_list>
Expand Down Expand Up @@ -189,7 +188,7 @@ static void FullContainerStressTest(TGen t)
EXPECT_TRUE(sm.size() == static_cast<typename SM::size_type>(total - i));
EXPECT_TRUE(sm.find(keys[i]) != sm.end());
EXPECT_TRUE(sm.find_unchecked(keys[i]) != sm.end());
for (int j = 0; j < i; ++j) {
for (int j = std::max(0, i - 10); j < i; ++j) {
EXPECT_TRUE(sm.find(keys[j]) == sm.end());
}
auto erased = sm.erase(keys[i]);
Expand All @@ -210,9 +209,9 @@ static void InsertEraseStressTest(TGen t)
auto k = sm.insert(t());
valid_keys.push_back(k);
}
std::shuffle(valid_keys.begin(), valid_keys.end(), g);
for (int i = total / 3; i < total; ++i) {
if (g() % 2 == 0 && !valid_keys.empty()) {
std::shuffle(valid_keys.begin(), valid_keys.end(), g);
auto k = valid_keys.back();
valid_keys.pop_back();
auto erased = sm.erase(k);
Expand All @@ -223,7 +222,8 @@ static void InsertEraseStressTest(TGen t)
}
} else {
auto k = sm.insert(t());
valid_keys.push_back(k);
size_t random_index = g() % (valid_keys.size() + 1);
valid_keys.insert(valid_keys.begin() + random_index, k);
}
}
}
Expand Down Expand Up @@ -281,7 +281,7 @@ static void EraseRangeTest()
EXPECT_TRUE(test(10, 1, 10));
EXPECT_TRUE(test(10, 0, 9));
EXPECT_TRUE(test(10, 1, 9));
for (int N : { 2, 10, 100 }) {
for (int N : { 2, 10, 50 }) {
for (int i=0; i < N; ++i) {
for (int j=i; j < N; ++j) {
EXPECT_TRUE(test(N, i, j));
Expand Down
1 change: 0 additions & 1 deletion test/uninitialized_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include <algorithm>
#include <array>
#include <cassert>
#include <ctime>
#include <iostream>
#include <memory>
Expand Down
Loading