From c2fdca90e0347c48a3a2a80ae92d11c2283d4e04 Mon Sep 17 00:00:00 2001 From: denes Date: Thu, 3 Oct 2019 16:37:05 +0200 Subject: [PATCH] Dummy calculation to measure --- CMakeLists.txt | 3 +++ main.cpp | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..0df3d49 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required (VERSION 3.10) +project (PerformanceMeasuring) +add_executable(performance_measuring main.cpp) diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..d654b7c --- /dev/null +++ b/main.cpp @@ -0,0 +1,35 @@ +#include +#include + +#include +#include + + +std::vector generate_random_numbers(int n, int min, int max) +{ + std::srand(std::time(nullptr)); + std::vector v(n); + for (int i = 0; i < n; ++i) + v[i] = min + std::rand() / ((RAND_MAX + 1u)/max); + + return v; +} + +int compute(const std::vector& v) +{ + int min = *std::min_element(v.begin(), v.end()); + return std::count(v.begin(), v.end(), min); +} + +int main(int /*argc*/, char* /*argv*/[]) +{ + std::vector v = generate_random_numbers(10000, 0, 100); + + // How many times does the smallest element occurst in the vector? + + int r = compute(v); + + (void)r; + + return EXIT_SUCCESS; +}