Initial commit

This commit is contained in:
Alexander Kobjolke 2025-03-13 22:36:51 +01:00
commit 4f4397b3e1
48 changed files with 2002 additions and 0 deletions

View file

@ -0,0 +1,39 @@
#pragma once
#include "../../time/time.h"
#include "../VectorFactory.h"
#include <chrono>
#include <iostream>
namespace atlas::collection::decorator {
template <typename T>
class MeasuredVectorFactory : public VectorFactory<T> {
public:
using decorated_type = VectorFactory<T>;
using decorated_ptr = std::unique_ptr<decorated_type>;
using stopwatch_ptr = std::unique_ptr<time::Timer<std::chrono::milliseconds>>;
MeasuredVectorFactory(stopwatch_ptr stopwatch, decorated_ptr decorated)
: m_stopwatch { std::move(stopwatch) }
, m_decorated { std::move(decorated) }
{
}
auto createAndFillVector(size_t const size) -> typename decorated_type::product_type override final
{
return logTimerResult(m_stopwatch->measure(
[this, size] { return m_decorated->createAndFillVector(size); }));
}
private:
template <typename Result>
auto logTimerResult(Result&& result) const
{
std::cout << "Duration: " << result.duration.count() << "ms\n";
return result.value;
}
stopwatch_ptr m_stopwatch;
decorated_ptr m_decorated;
};
}