-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e133333
commit 0a112d5
Showing
4 changed files
with
114 additions
and
4 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
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,74 @@ | ||
#ifndef _MKN_TEST_INSTRUMENT_ALLOC_HPP_ | ||
#define _MKN_TEST_INSTRUMENT_ALLOC_HPP_ | ||
|
||
#include "mkn/kul/dbg.hpp" | ||
#include "mkn/kul/vector.hpp" | ||
|
||
#include <array> | ||
#include <cstddef> | ||
#include <algorithm> | ||
|
||
template <std::size_t size = 8> | ||
struct S { | ||
S() { | ||
for (std::size_t i = 0; i < size; i++) vars[i] = i; | ||
} | ||
|
||
bool operator==(S const& that) const { | ||
return std::equal(vars.begin(), vars.end(), that.vars.begin()); | ||
} | ||
|
||
bool operator!=(S const& that) const { return !(*this == that); } | ||
auto& operator[](std::uint8_t const i) const { return vars[i]; } | ||
std::array<std::size_t, size> vars; | ||
}; | ||
|
||
template <typename V> | ||
auto copy_construct(V const& v) { | ||
KUL_DBG_FUNC_ENTER; | ||
V out{v}; | ||
return out; | ||
} | ||
|
||
template <typename V> | ||
auto copy_operator_equal(V const& v) { | ||
KUL_DBG_FUNC_ENTER; | ||
V out; | ||
out.reserve(v.capacity()); | ||
out = v; | ||
return out; | ||
} | ||
|
||
template <typename V> | ||
auto copy_operator_equal_super(V const& v) { | ||
KUL_DBG_FUNC_ENTER; | ||
V out; | ||
out.reserve(v.capacity()); | ||
mkn::kul::as_super(out) = mkn::kul::as_super(v); | ||
return out; | ||
} | ||
|
||
template <typename V> | ||
auto copy_manual(V const& v) { | ||
KUL_DBG_FUNC_ENTER; | ||
V out; | ||
out.reserve(v.capacity()); | ||
out.resize(v.size()); | ||
std::copy(v.begin(), v.end(), out.begin()); | ||
return out; | ||
} | ||
|
||
template <typename V> | ||
auto make_vector(std::size_t const& size) { | ||
KUL_DBG_FUNC_ENTER; | ||
return V(size); | ||
} | ||
template <typename V0, typename V1> | ||
auto make_vector_from(V1 const& v1) { | ||
KUL_DBG_FUNC_ENTER; | ||
V0 v(v1.size()); | ||
std::copy(v1.begin(), v1.end(), v.begin()); | ||
return v; | ||
} | ||
|
||
#endif /*_MKN_TEST_INSTRUMENT_ALLOC_HPP_*/ |
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,18 @@ | ||
#include <stdexcept> | ||
#include <string_view> | ||
#include "test/instrument/alloc.hpp" | ||
|
||
std::string_view constexpr RUN = | ||
R"( | ||
mkn -p base -M test/instrument/non_constructing_vector.cpp -Og 0 build -b . run -a -fPIC -x clang -m "clang.llvm-mca{link{bin: llvm-mca-19, out: non_vec.txt}}" | ||
)"; | ||
|
||
template <typename T> | ||
void go() { | ||
constexpr static std::size_t N = 2000000; | ||
auto const std_vec = make_vector<std::vector<T>>(N); | ||
auto const std_vec2 = make_vector_from<mkn::kul::NonConstructingVector<T>>(std_vec); | ||
if (std_vec2[0][0] != 0) throw std::runtime_error("do not optimize out"); | ||
} | ||
|
||
int main() { go<S<8>>(); } |
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,18 @@ | ||
#include <stdexcept> | ||
#include <string_view> | ||
#include "test/instrument/alloc.hpp" | ||
|
||
std::string_view constexpr RUN = | ||
R"( | ||
mkn -p base -M test/instrument/std_vector.cpp -Og 0 build -b . run -a -fPIC -x clang -m "clang.llvm-mca{link{bin: llvm-mca-19, out: std_vec.txt}}" | ||
)"; | ||
|
||
template <typename T> | ||
void go() { | ||
constexpr static std::size_t N = 2000000; | ||
auto const std_vec = make_vector<std::vector<T>>(N); | ||
auto const std_vec2 = make_vector_from<std::vector<T>>(std_vec); | ||
if (std_vec2[0][0] != 0) throw std::runtime_error("do not optimize out"); | ||
} | ||
|
||
int main() { go<S<8>>(); } |