parent
ea78131ced
commit
c2fdca90e0
@ -0,0 +1,3 @@
|
||||
cmake_minimum_required (VERSION 3.10)
|
||||
project (PerformanceMeasuring)
|
||||
add_executable(performance_measuring main.cpp)
|
@ -0,0 +1,35 @@
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
std::vector<int> generate_random_numbers(int n, int min, int max)
|
||||
{
|
||||
std::srand(std::time(nullptr));
|
||||
std::vector<int> 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<int>& 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<int> 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;
|
||||
}
|
Loading…
Reference in new issue