diff --git a/worksheet_two/task_3/benchmark.hpp b/worksheet_two/task_3/benchmark.hpp new file mode 100644 index 0000000000000000000000000000000000000000..23cbf2771eca457e09dd0e7c51a176c4f866c377 --- /dev/null +++ b/worksheet_two/task_3/benchmark.hpp @@ -0,0 +1,23 @@ +#ifndef BENCHMARK_HPP +#define BENCHMARK_HPP + +#include <chrono> +#include <iostream> +#include <functional> +#include <string> + +class Benchmark { +public: + // Function to measure the time of a void function + static void measure(const std::string& name, const std::function<void()>& func) { + using namespace std::chrono; + auto start = high_resolution_clock::now(); + func(); // Run the function + auto end = high_resolution_clock::now(); + auto duration = duration_cast<milliseconds>(end - start); + + std::cout << "Benchmark \"" << name << "\": " << duration.count() << " ms\n"; + } +}; + +#endif