diff --git a/benchmark/helpers/randomizers.h b/benchmark/helpers/randomizers.h index 302dfdc..962ce7d 100644 --- a/benchmark/helpers/randomizers.h +++ b/benchmark/helpers/randomizers.h @@ -11,27 +11,33 @@ #include #include -// Global seed value for random number generator -constexpr unsigned int DefaultSeed = 937162211; // Using a long prime number as our default seed +namespace ccm::bench +{ + struct Randomizer + { + public: + explicit Randomizer(std::uint_fast32_t seed = 937162211) : m_gen{seed} {} -// Generate a fixed set of random integers for benchmarking -std::vector generateRandomIntegers(size_t count, unsigned int seed) { - std::vector randomIntegers; - std::mt19937 gen(seed); - std::uniform_int_distribution dist(std::numeric_limits::min(), std::numeric_limits::max()); - for (size_t i = 0; i < count; ++i) { - randomIntegers.push_back(dist(gen)); - } - return randomIntegers; -} + std::vector generateRandomIntegers(std::size_t count, int min = std::numeric_limits::min(), int max = std::numeric_limits::max()) + { + std::vector randomIntegers; + randomIntegers.reserve(count); + std::uniform_int_distribution dist(min, max); + for (std::size_t i = 0; i < count; ++i) { randomIntegers.push_back(dist(m_gen)); } + return randomIntegers; + } -// Generate a fixed set of random integers for benchmarking -std::vector generateRandomDoubles(size_t count, unsigned int seed) { - std::vector randomDouble; - std::mt19937 gen(seed); - std::uniform_real_distribution dist(std::numeric_limits::min(), std::numeric_limits::max()); - for (size_t i = 0; i < count; ++i) { - randomDouble.push_back(dist(gen)); - } - return randomDouble; -} + std::vector generateRandomDoubles(std::size_t count, double min = 0.0, + double max = 1.0) + { + std::vector randomDouble; + randomDouble.reserve(count); + std::uniform_real_distribution dist(min, max); + for (std::size_t i = 0; i < count; ++i) { randomDouble.push_back(dist(m_gen)); } + return randomDouble; + } + + private: + std::mt19937 m_gen; + }; +} // namespace ccm::bench \ No newline at end of file diff --git a/scripts/run_benchmark_and_plot.bat b/scripts/run_benchmark_and_plot.bat new file mode 100755 index 0000000..197c2d2 --- /dev/null +++ b/scripts/run_benchmark_and_plot.bat @@ -0,0 +1,36 @@ +@echo off +set SCRIPTS_DIR=%~dp0 +cd /d "%SCRIPTS_DIR%.." +set ROOT_DIR=%CD% + +rem Check that root directory is set as ccmath +for %%I in ("%ROOT_DIR%") do set BASENAME=%%~nI +if not "%BASENAME%"=="ccmath" ( + echo Please run this script from the scripts folder inside of the ccmath root directory + exit /b 1 +) + +echo Preparing ccmath for benchmarking and plot generation... + +rem if out-plot directory exists, remove it +if exist "%ROOT_DIR%\out-plot" ( + echo Removing existing out-plot directory... + rmdir /s /q "%ROOT_DIR%\out-plot" +) + +cd /d "%ROOT_DIR%" || exit /b 1 +cmake -S . --preset=default -B out-plot -DCCMATH_BUILD_BENCHMARKS:BOOL=ON -DCCMATH_BUILD_TESTS:BOOL=OFF -DCCMATH_BUILD_EXAMPLES:BOOL=OFF +cmake --build out-plot --config Release + +rem Store the generated benchmark directory +set "BENCHMARK_EXE=%ROOT_DIR%\out-plot\benchmark\Release\ccmath-benchmark" + +rem Move into the benchmark build directory +cd /d "%ROOT_DIR%\out-plot\benchmark\Release" || exit /b 1 + +rem Generate the benchmark csv file +%BENCHMARK_EXE% --benchmark_format=csv > benchmark.csv + +echo Creating graph now! +rem Pass the csv file to the plot script to generate our graph +python "%SCRIPTS_DIR%\plot.py" -f benchmark.csv diff --git a/scripts/run_benchmark_and_plot.sh b/scripts/run_benchmark_and_plot.sh index 23f9c0e..abbcbf7 100755 --- a/scripts/run_benchmark_and_plot.sh +++ b/scripts/run_benchmark_and_plot.sh @@ -32,6 +32,4 @@ ${BENCHMARK_EXE} --benchmark_format=csv > benchmark.csv echo "Creating graph now!" # Pass the csv file to the plot script to generate our graph -python3 "${SCRIPTS_DIR}/plot.py" -f benchmark.csv - -# Run the benchmark and plot +python3 "${SCRIPTS_DIR}/plot.py" -f benchmark.csv \ No newline at end of file