Skip to content
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
5 changes: 3 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ jobs:
- name: run tests
run: |
pip install ddt requests
python -v tests/full_corpus/test_full_corpus.py
python -v tests/full_corpus/test.py

test_wheels_macos_14:
needs: [build_wheels]
Expand All @@ -125,6 +125,7 @@ jobs:
echo "~/.pyenv/shims" >> $GITHUB_PATH
- name: install dependencies
run: |
brew cleanup --prune=all && rm -rf "$(brew --cache)"
brew update
brew install pyenv
pyenv install ${{ matrix.python-version }}
Expand All @@ -143,7 +144,7 @@ jobs:
run: |
pyenv local ${{ matrix.python-version }}
python3 -m pip install --break-system-packages ddt requests
python3 tests/full_corpus/test_full_corpus.py
python3 tests/full_corpus/test.py


upload_pypi:
Expand Down
15 changes: 11 additions & 4 deletions .github/workflows/tests-with-coverage.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: Tests Linux with coverage

on: [push]
on:
push:
pull_request:

jobs:
build:
Expand All @@ -10,11 +12,16 @@ jobs:
- uses: actions/checkout@v6
with:
submodules: true
- name: Install dependencies
- name: Install system dependencies
run: |
sudo apt update
sudo apt install -y python3-pip python3-dev lcov g++ catch2
pip install --upgrade meson ninja numpy meson-python>=0.14.0 build wheel ddt requests
sudo apt install -y lcov g++ catch2
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: '3.13'
- name: Install Python dependencies
run: python3.13 -m pip install meson ninja numpy meson-python>=0.14.0 build wheel ddt requests
- name: Configure with meson
run: meson -Db_coverage=true -Dwith_tests=true . build
- name: Build (meson)
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ subprojects/*
CMakeLists.txt.user
.cache/*
.cmake/*
.idea/*
*.user
*.user.*
*.ipynb_check*
*__pycache__*
*.patch
version.txt
docs/_build/*
docs/generated/*
Expand Down
1 change: 1 addition & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ build:
apt_packages:
- g++
- ninja-build
- cmake
tools:
python: "3.12"
# You can also specify other tool versions:
Expand Down
168 changes: 168 additions & 0 deletions benchmarks/chrono/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
#include <benchmark/benchmark.h>
#include <cdfpp/chrono/cdf-chrono.hpp>
#include <cstring>

inline constexpr std::size_t mega(std::size_t n)
{
return n * 1024 * 1024;
}

template <typename T>
no_init_vector<T> generate_sorted_time_vectors(T start, T end, std::size_t count)
{
T step = (end - start) / count;
no_init_vector<T> result(count);
for (auto& v : result)
{
v = T(start);
start += step;
}
return result;
}

template <cdf::cdf_time_t T>
inline auto& value_ref(T& t)
{
if constexpr (std::is_same_v<T, cdf::tt2000_t>)
{
return t.nseconds;
}
else if constexpr (std::is_same_v<T, cdf::epoch>)
{
return t.mseconds;
}
else if constexpr (std::is_same_v<T, cdf::epoch16>)
{
return t.seconds;
}
}


template <cdf::cdf_time_t T>
no_init_vector<T> generate_sorted_time_vectors(T start, T end, std::size_t count)
{
T step((value_ref(end) - value_ref(start)) / count);
no_init_vector<T> result(count);
for (auto& v : result)
{
v = start;
value_ref(start) += value_ref(step);
}
return result;
}


template <typename leap_func_t>
static void BM_leap_second(benchmark::State& state, leap_func_t leap_func)
{
constexpr std::size_t start = 63'072'000'000'000'000;
constexpr std::size_t end = 2'081'948'754'000'000'000;

const auto time_vect = generate_sorted_time_vectors<int64_t>(start, end, state.range(0));
for (auto _ : state)
{
int64_t leap = 0;
for (const auto& time : time_vect)
{
leap ^= leap_func(time);
}
benchmark::DoNotOptimize(leap);
}
state.counters["Epochs"] = std::size(time_vect);
state.counters["epochs_per_second"]
= benchmark::Counter(std::size(time_vect), benchmark::Counter::kIsIterationInvariantRate);
}
BENCHMARK_CAPTURE(BM_leap_second, branchless, cdf::chrono::_impl::leap_second_branchless)
->RangeMultiplier(4)
->Range(100, mega(64))
->Complexity();

BENCHMARK_CAPTURE(
BM_leap_second, baseline, static_cast<int64_t (*)(int64_t)>(cdf::chrono::_impl::leap_second))
->RangeMultiplier(4)
->Range(100, mega(64))
->Complexity();

template <typename time_t, typename func_t>
static void BM_to_ns_from_1970(benchmark::State& state, func_t func, time_t start, time_t end)
{
const auto time_vect = generate_sorted_time_vectors<time_t>(start, end, state.range(0));
no_init_vector<int64_t> output(time_vect.size());
for (auto _ : state)
{
benchmark::ClobberMemory();
func(time_vect, output.data());
benchmark::DoNotOptimize(output);
}
state.counters["Epochs"] = std::size(time_vect);
state.counters["epochs_per_second"]
= benchmark::Counter(std::size(time_vect), benchmark::Counter::kIsIterationInvariantRate);
}

BENCHMARK_CAPTURE(BM_to_ns_from_1970, tt2000_scalar,
static_cast<void (*)(const std::span<const cdf::tt2000_t>&, int64_t* const)>(
cdf::chrono::_impl::scalar_to_ns_from_1970),
cdf::tt2000_t{63'072'000'000'000'000},
cdf::tt2000_t{2'081'948'754'000'000'000}
)
->RangeMultiplier(4)
->Range(10, mega(1024))
->Complexity()
->UseRealTime();

BENCHMARK_CAPTURE(BM_to_ns_from_1970, tt2000_vectorized,
static_cast<void (*)(const std::span<const cdf::tt2000_t>&, int64_t* const)>(
vectorized_to_ns_from_1970),
cdf::tt2000_t{63'072'000'000'000'000},
cdf::tt2000_t{2'081'948'754'000'000'000}
)
->RangeMultiplier(4)
->Range(10, mega(1024))
->Complexity()
->UseRealTime();

BENCHMARK_CAPTURE(BM_to_ns_from_1970, tt2000_entry_point,
static_cast<void (*)(const std::span<const cdf::tt2000_t>& , int64_t* const)>(
cdf::to_ns_from_1970),
cdf::tt2000_t{63'072'000'000'000'000},
cdf::tt2000_t{2'081'948'754'000'000'000}
)
->RangeMultiplier(4)
->Range(10, mega(1024))
->Complexity()
->UseRealTime();

BENCHMARK_CAPTURE(BM_to_ns_from_1970, epoch_scalar,
static_cast<void (*)(const std::span<const cdf::epoch>&, int64_t* const)>(
cdf::chrono::_impl::scalar_to_ns_from_1970),
cdf::epoch{62167215600000.0},
cdf::epoch{63745052400000.0}
)
->RangeMultiplier(4)
->Range(10, mega(1024))
->Complexity()
->UseRealTime();

BENCHMARK_CAPTURE(BM_to_ns_from_1970, epoch_vectorized,
static_cast<void (*)(const std::span<const cdf::epoch>&, int64_t* const)>(
vectorized_to_ns_from_1970),
cdf::epoch{62167215600000.0},
cdf::epoch{63745052400000.0}
)
->RangeMultiplier(4)
->Range(10, mega(1024))
->Complexity()
->UseRealTime();

BENCHMARK_CAPTURE(BM_to_ns_from_1970, epoch_entry_point,
static_cast<void (*)(const std::span<const cdf::epoch>&, int64_t* const)>(
cdf::to_ns_from_1970),
cdf::epoch{62167215600000.0},
cdf::epoch{63745052400000.0}
)
->RangeMultiplier(4)
->Range(10, mega(1024))
->Complexity()
->UseRealTime();

BENCHMARK_MAIN();
8 changes: 8 additions & 0 deletions benchmarks/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
google_benchmarks_dep = dependency('benchmark', required : true)
foreach bench:['file_reader', 'chrono']
exe = executable('benchmark-'+bench, bench+'/main.cpp',
dependencies:[google_benchmarks_dep, cdfpp_dep],
install: false
)
benchmark(bench, exe)
endforeach
18 changes: 18 additions & 0 deletions include/cdfpp/cdf-debug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
/*-- Author : Alexis Jeandet
-- Mail : alexis.jeandet@member.fsf.org
----------------------------------------------------------------------------*/
#include <source_location>

#include <fmt/core.h>
#include <fmt/std.h>
#include <fmt/ranges.h>

#pragma once
#ifdef CDFPP_ENABLE_ASSERT
#include <cassert>
Expand All @@ -44,3 +50,15 @@
#define CDFPP_DIAGNOSTIC_DISABLE_DEPRECATED
#define CDFPP_DIAGNOSTIC_POP
#endif

[[nodiscard]] constexpr auto exception_message(const auto& msg,
const std::source_location& location = std::source_location::current())
{
return fmt::format(
R"(
{}
at {}:{} in function {}
)",
msg, location.file_name(), location.line(), location.function_name());
}

Loading
Loading