Skip to content

Commit 0f31ee9

Browse files
committed
Benchmarks: mt19937 as random
1 parent 5d6861b commit 0f31ee9

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

.github/workflows/benchmarks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
- 'octree.h'
99
- 'octree_container.h'
1010
- 'benchmarks/automatic/main.cpp'
11+
- 'benchmarks/manual/generators.h'
1112

1213
permissions:
1314
contents: write

benchmarks/manual/generators.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22
#include <vector>
3+
#include <random>
34

45
#include "../../octree.h"
56

@@ -10,6 +11,7 @@ auto constexpr rMax = 8.0;
1011
template<dim_t DIMENSION_NO>
1112
constexpr std::vector<PointND<DIMENSION_NO>> GeneratePointsRandom(size_t pointsNo, int seed = 0)
1213
{
14+
auto rng = std::mt19937(seed);
1315

1416
auto aPoint = std::vector<PointND<DIMENSION_NO>>(pointsNo);
1517
if (pointsNo <= 1)
@@ -31,11 +33,10 @@ constexpr std::vector<PointND<DIMENSION_NO>> GeneratePointsRandom(size_t pointsN
3133
aPoint[iNumber][iDim] = rMax;
3234
}
3335

34-
srand(seed);
3536
{
3637
for (; iNumber < pointsNo; ++iNumber)
3738
for (dim_t iDim = 0; iDim < DIMENSION_NO; ++iDim)
38-
aPoint[iNumber][iDim] = double(rand() % 100) * (rMax / 100.0);
39+
aPoint[iNumber][iDim] = double(rng() % 100) * (rMax / 100.0);
3940
}
4041

4142
return aPoint;
@@ -83,7 +84,7 @@ BoundingBoxND<DIMENSION_NO> CreateSearcBox(double rBegin, double rSize)
8384

8485

8586
template<dim_t DIMENSION_NO>
86-
constexpr std::vector<BoundingBoxND<DIMENSION_NO>> GenerateBoxesRandom(size_t nNumber, int seed = 0)
87+
constexpr std::vector<BoundingBoxND<DIMENSION_NO>> GenerateBoxesRandom(size_t nNumber, int seed = 0, double boxSizeScale = 0.125)
8788
{
8889
if (nNumber == 0)
8990
return {};
@@ -116,16 +117,18 @@ constexpr std::vector<BoundingBoxND<DIMENSION_NO>> GenerateBoxesRandom(size_t nN
116117
++iNumber;
117118
}
118119

119-
srand(seed);
120+
auto rng = std::mt19937(seed);
120121

121122
{
123+
auto const rMaxBoxSize = boxSizeScale * rMax;
122124
for (size_t iRemain = 1; iNumber < nNumber; ++iNumber, ++iRemain)
123125
{
124126
auto const iNumberBox = nNumber - iNumber - 1;
125127
for (dim_t iDim = 0; iDim < DIMENSION_NO && iNumber < nNumber; ++iDim)
126-
aBox[iNumberBox].Min[iDim] = double(rand() % 100) * ((rMax - 1.0) / 100.0);
127-
128-
aBox[iNumberBox].Max = CreateBoxMax(aBox[iNumberBox].Min, double(rand() % 100) * (1.0 * rUnit / 100.0));
128+
{
129+
aBox[iNumberBox].Min[iDim] = double(rng() % 100) * ((rMax - 1.0) / 100.0);
130+
aBox[iNumberBox].Max[iDim] = std::min(rMax, aBox[iNumberBox].Min[iDim] + (double(rng() % 100) / 100.0) * rMaxBoxSize);
131+
}
129132
}
130133
}
131134

0 commit comments

Comments
 (0)