Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple minimally working metrics (#214)
- Loading branch information
Showing
24 changed files
with
1,637 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright (c) 2023 Morwenn | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
#include <cstdint> | ||
#include <utility> | ||
#include <cpp-sort/utility/adapter_storage.h> | ||
#include <cpp-sort/utility/metrics_tools.h> | ||
#include <cpp-sort/detail/checkers.h> | ||
#include "rdtsc.h" | ||
|
||
//////////////////////////////////////////////////////////// | ||
// Tag | ||
|
||
struct cpu_cycles_tag {}; | ||
|
||
//////////////////////////////////////////////////////////// | ||
// Metric | ||
|
||
template<typename Sorter> | ||
struct cpu_cycles: | ||
cppsort::utility::adapter_storage<Sorter>, | ||
cppsort::detail::check_iterator_category<Sorter>, | ||
cppsort::detail::check_is_always_stable<Sorter>, | ||
cppsort::detail::sorter_facade_fptr< | ||
cpu_cycles<Sorter>, | ||
std::is_empty_v<Sorter> | ||
> | ||
{ | ||
using tag_t = cpu_cycles_tag; | ||
using metric_t = cppsort::utility::metric<unsigned long long, tag_t>; | ||
|
||
cpu_cycles() = default; | ||
|
||
constexpr explicit cpu_cycles(Sorter sorter): | ||
cppsort::utility::adapter_storage<Sorter>(std::move(sorter)) | ||
{} | ||
|
||
template<typename... Args> | ||
auto operator()(Args&&... args) const | ||
-> decltype( | ||
this->get()(std::forward<Args>(args)...), | ||
metric_t(std::declval<unsigned long long>()) | ||
) | ||
{ | ||
auto start = ::rdtsc(); | ||
this->get()(std::forward<Args>(args)...); | ||
auto stop = ::rdtsc(); | ||
return metric_t(stop - start); | ||
} | ||
}; | ||
|
||
//////////////////////////////////////////////////////////// | ||
// is_stable specialization | ||
|
||
namespace cppsort | ||
{ | ||
template<typename Sorter, typename... Args> | ||
struct is_stable<cpu_cycles<Sorter>(Args...)>: | ||
is_stable<Sorter(Args...)> | ||
{}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.