Skip to content

Commit

Permalink
Auto stash before revert of "trim down contributing docs"
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinzii committed Apr 17, 2024
1 parent 0a26ba6 commit b6ad28a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 25 deletions.
50 changes: 28 additions & 22 deletions benchmark/helpers/randomizers.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,33 @@
#include <random>
#include <vector>

// 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<int> generateRandomIntegers(size_t count, unsigned int seed) {
std::vector<int> randomIntegers;
std::mt19937 gen(seed);
std::uniform_int_distribution dist(std::numeric_limits<int>::min(), std::numeric_limits<int>::max());
for (size_t i = 0; i < count; ++i) {
randomIntegers.push_back(dist(gen));
}
return randomIntegers;
}
std::vector<int> generateRandomIntegers(std::size_t count, int min = std::numeric_limits<int>::min(), int max = std::numeric_limits<int>::max())
{
std::vector<int> 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<double> generateRandomDoubles(size_t count, unsigned int seed) {
std::vector<double> randomDouble;
std::mt19937 gen(seed);
std::uniform_real_distribution dist(std::numeric_limits<double>::min(), std::numeric_limits<double>::max());
for (size_t i = 0; i < count; ++i) {
randomDouble.push_back(dist(gen));
}
return randomDouble;
}
std::vector<double> generateRandomDoubles(std::size_t count, double min = 0.0,
double max = 1.0)
{
std::vector<double> 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
36 changes: 36 additions & 0 deletions scripts/run_benchmark_and_plot.bat
Original file line number Diff line number Diff line change
@@ -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
4 changes: 1 addition & 3 deletions scripts/run_benchmark_and_plot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b6ad28a

Please sign in to comment.