diff --git a/.gitmodules b/.gitmodules index 2f24b84..6a61780 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "Catch2"] path = Catch2 url = https://github.com/catchorg/Catch2.git +[submodule "FlameGraph"] + path = FlameGraph + url = https://github.com/brendangregg/FlameGraph.git diff --git a/CMakeLists.txt b/CMakeLists.txt index ef04e43..054b94b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,12 @@ cmake_minimum_required (VERSION 3.10) 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}) -target_include_directories(performance_measuring PRIVATE . Catch2/single_include) +set(CATCH_HEADER_FILES dummy_lib.hpp Catch2/single_include/catch2/catch.hpp) +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 .) diff --git a/FlameGraph b/FlameGraph new file mode 160000 index 0000000..1b1c6de --- /dev/null +++ b/FlameGraph @@ -0,0 +1 @@ +Subproject commit 1b1c6deede9c33c5134c920bdb7a44cc5528e9a7 diff --git a/Jenkinsfile b/Jenkinsfile index 5b3d45c..0d29336 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -15,11 +15,19 @@ pipeline { } } - stage('Run') { + stage('Running catch2 tests') { steps { - sh 'performance_measuring' + sh 'performance_measuring_test' + } + } + + stage('Generatin flamegraph') { + steps { + sh 'generate_flame_graph.sh' + archiveArtifacts artifacts: 'flamegraph.svg', fingerprint: true } } } } + diff --git a/catch2_test1.cpp b/catch2_test1.cpp index 8bb3858..9bc7e38 100644 --- a/catch2_test1.cpp +++ b/catch2_test1.cpp @@ -16,6 +16,8 @@ std::vector generate_random_numbers(int n, int min, int max) return v; } +// How many times the smallest element occurts in a vector? + TEST_CASE( "Simple test" ) { std::vector v = { 1, 2, 3, 1}; REQUIRE( performance_measuring::count_on_the_way(v) == 2 ); diff --git a/dummy_lib.hpp b/dummy_lib.hpp index bc62e4a..7315f6f 100644 --- a/dummy_lib.hpp +++ b/dummy_lib.hpp @@ -4,6 +4,8 @@ #include #include +// How many times the smallest element occurts in a vector? + namespace performance_measuring { int count_on_the_way(const std::vector& v) diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..e1db687 --- /dev/null +++ b/main.cpp @@ -0,0 +1,35 @@ +#include +#include +#include + +#include + +#include "dummy_lib.hpp" + + +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 main(int /*argc*/, char* /*argv*/[]) +{ + std::vector 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; +} +