Skip to content

Commit

Permalink
Enable warnings for the benchmarks, and fix them (#4356)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanTLavavej authored Feb 1, 2024
1 parent 3d9ade1 commit 55b8971
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 17 deletions.
3 changes: 3 additions & 0 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ endif()

set(CMAKE_BUILD_TYPE RelWithDebInfo)

# /utf-8 affects <format>.
add_compile_options("$<$<COMPILE_LANGUAGE:CXX>:/diagnostics:caret;/W4;/WX;/w14265;/w15038;/w15262;/utf-8>")

if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/google-benchmark/.git")
message(FATAL_ERROR "google-benchmark is not checked out; make sure to run\n git submodule update --init benchmarks/google-benchmark")
endif()
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/inc/udt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@

#pragma once

template <typename Contained>
template <typename Data>
struct aggregate {
Contained c;
Data c;

friend bool operator==(const aggregate&, const aggregate&) = default;
};

template <typename Contained>
template <typename Data>
struct non_trivial {
Contained c;
Data c;
non_trivial() : c() {}
non_trivial(const Contained& src) : c(src) {}
non_trivial(const Data& src) : c(src) {}
non_trivial(const non_trivial& other) : c(other.c) {}
non_trivial& operator=(const non_trivial& other) {
c = other.c;
Expand Down
9 changes: 9 additions & 0 deletions benchmarks/inc/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ std::vector<Contained> random_vector(size_t n) {
xoshiro256ss prng{id64(rd), id64(rd), id64(rd), id64(rd)};

std::vector<Contained> res(n);

// Here, the type Contained can be char, int, aggregate<Data>, or non_trivial<Data> where Data is char or int.
// (aggregate<Data> and non_trivial<Data> are defined in udt.hpp.)
// static_cast<Contained> silences truncation warnings when Contained is directly char or int,
// but is insufficient for aggregate<Data> or non_trivial<Data>.
#pragma warning(push)
#pragma warning(disable : 4244) // warning C4244: conversion from 'uint64_t' to 'Data', possible loss of data
std::generate(res.begin(), res.end(), [&prng] { return static_cast<Contained>(prng.next()); });
#pragma warning(pop)

return res;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <benchmark/benchmark.h>
//
#include <algorithm>
#include <cstddef>
#include <random>
#include <vector>

Expand All @@ -17,7 +18,7 @@ static vector<bool> createRandomVector(const size_t size) {
}

static void copy_block_aligned(benchmark::State& state) {
const auto size = state.range(0);
const auto size = static_cast<size_t>(state.range(0));
const vector<bool> source = createRandomVector(size);
vector<bool> dest(size, false);

Expand All @@ -27,7 +28,7 @@ static void copy_block_aligned(benchmark::State& state) {
}

static void copy_source_misaligned(benchmark::State& state) {
const auto size = state.range(0);
const auto size = static_cast<size_t>(state.range(0));
const vector<bool> source = createRandomVector(size);
vector<bool> dest(size, false);

Expand All @@ -37,7 +38,7 @@ static void copy_source_misaligned(benchmark::State& state) {
}

static void copy_dest_misaligned(benchmark::State& state) {
const auto size = state.range(0);
const auto size = static_cast<size_t>(state.range(0));
const vector<bool> source = createRandomVector(size);
vector<bool> dest(size, false);

Expand All @@ -48,7 +49,7 @@ static void copy_dest_misaligned(benchmark::State& state) {

// Special benchmark for matching char alignment
static void copy_matching_alignment(benchmark::State& state) {
const auto size = state.range(0);
const auto size = static_cast<size_t>(state.range(0));
const vector<bool> source = createRandomVector(size);
vector<bool> dest(size, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <benchmark/benchmark.h>
//
#include <algorithm>
#include <cstddef>
#include <random>
#include <vector>

Expand All @@ -17,7 +18,7 @@ static vector<bool> createRandomVector(const size_t size) {
}

static void copy_n_block_aligned(benchmark::State& state) {
const auto size = state.range(0);
const auto size = static_cast<size_t>(state.range(0));
const vector<bool> source = createRandomVector(size);
vector<bool> dest(size, false);

Expand All @@ -27,7 +28,7 @@ static void copy_n_block_aligned(benchmark::State& state) {
}

static void copy_n_source_misaligned(benchmark::State& state) {
const auto size = state.range(0);
const auto size = static_cast<size_t>(state.range(0));
const vector<bool> source = createRandomVector(size);
vector<bool> dest(size, false);

Expand All @@ -37,7 +38,7 @@ static void copy_n_source_misaligned(benchmark::State& state) {
}

static void copy_n_dest_misaligned(benchmark::State& state) {
const auto size = state.range(0);
const auto size = static_cast<size_t>(state.range(0));
const vector<bool> source = createRandomVector(size);
vector<bool> dest(size, false);

Expand All @@ -48,7 +49,7 @@ static void copy_n_dest_misaligned(benchmark::State& state) {

// Special benchmark for matching char alignment
static void copy_n_matching_alignment(benchmark::State& state) {
const auto size = state.range(0);
const auto size = static_cast<size_t>(state.range(0));
const vector<bool> source = createRandomVector(size);
vector<bool> dest(size, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <benchmark/benchmark.h>
//
#include <algorithm>
#include <cstddef>
#include <random>
#include <vector>

Expand All @@ -17,7 +18,7 @@ static vector<bool> createRandomVector(const size_t size) {
}

static void move_block_aligned(benchmark::State& state) {
const auto size = state.range(0);
const auto size = static_cast<size_t>(state.range(0));
const vector<bool> source = createRandomVector(size);
vector<bool> dest(size, false);

Expand All @@ -27,7 +28,7 @@ static void move_block_aligned(benchmark::State& state) {
}

static void move_source_misaligned(benchmark::State& state) {
const auto size = state.range(0);
const auto size = static_cast<size_t>(state.range(0));
const vector<bool> source = createRandomVector(size);
vector<bool> dest(size, false);

Expand All @@ -37,7 +38,7 @@ static void move_source_misaligned(benchmark::State& state) {
}

static void move_dest_misaligned(benchmark::State& state) {
const auto size = state.range(0);
const auto size = static_cast<size_t>(state.range(0));
const vector<bool> source = createRandomVector(size);
vector<bool> dest(size, false);

Expand All @@ -48,7 +49,7 @@ static void move_dest_misaligned(benchmark::State& state) {

// Special benchmark for matching char alignment
static void move_matching_alignment(benchmark::State& state) {
const auto size = state.range(0);
const auto size = static_cast<size_t>(state.range(0));
const vector<bool> source = createRandomVector(size);
vector<bool> dest(size, false);

Expand Down

0 comments on commit 55b8971

Please sign in to comment.