parent
8ee57e83e2
commit
3b26c69377
@ -1,3 +1,6 @@
|
|||||||
[submodule "Catch2"]
|
[submodule "Catch2"]
|
||||||
path = Catch2
|
path = Catch2
|
||||||
url = https://github.com/catchorg/Catch2.git
|
url = https://github.com/catchorg/Catch2.git
|
||||||
|
[submodule "FlameGraph"]
|
||||||
|
path = FlameGraph
|
||||||
|
url = https://github.com/brendangregg/FlameGraph.git
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
cmake_minimum_required (VERSION 3.10)
|
cmake_minimum_required (VERSION 3.10)
|
||||||
project (PerformanceMeasuring)
|
project (PerformanceMeasuring)
|
||||||
|
|
||||||
set(HEADER_FILES dummy_lib.hpp Catch2/single_include/catch2/catch.hpp)
|
set(CMAKE_CXX_FLAGS "-ggdb")
|
||||||
|
|
||||||
add_executable(performance_measuring catch2_test1.cpp ${HEADER_FILES})
|
set(CATCH_HEADER_FILES dummy_lib.hpp Catch2/single_include/catch2/catch.hpp)
|
||||||
target_include_directories(performance_measuring PRIVATE . Catch2/single_include)
|
add_executable(performance_measuring_test catch2_test1.cpp ${HEADER_FILES})
|
||||||
|
target_include_directories(performance_measuring_test PRIVATE . Catch2/single_include)
|
||||||
|
|
||||||
|
set(HEADER_FILES dummy_lib.hpp)
|
||||||
|
add_executable(performance_measuring main.cpp ${HEADER_FILES})
|
||||||
|
target_include_directories(performance_measuring PRIVATE .)
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 1b1c6deede9c33c5134c920bdb7a44cc5528e9a7
|
@ -0,0 +1,35 @@
|
|||||||
|
#include <cstdlib>
|
||||||
|
#include <ctime>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "dummy_lib.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
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 main(int /*argc*/, char* /*argv*/[])
|
||||||
|
{
|
||||||
|
std::vector<int> v = generate_random_numbers(10000, 0, 1000);
|
||||||
|
|
||||||
|
// How many times does the smallest element occursts in the vector?
|
||||||
|
|
||||||
|
int r1 = performance_measuring::count_on_the_way(v);
|
||||||
|
int r2 = performance_measuring::min_element_and_count(v);
|
||||||
|
int r3 = performance_measuring::sort_and_upper_bound(v);
|
||||||
|
|
||||||
|
assert(r1 == r2);
|
||||||
|
assert(r2 == r3);
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in new issue