-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(dev/benchmarks): Benchmark coordinate sequence iteration (#112)
This PR benchmarks coordinate iteration (and fixes the previous benchmarks benchmark the same cases). Some takeaways: - In C, `GEOARROW_COORD_VIEW_VALUE()`, which uses `i * coord_stride`, seems to prevent the compiler from doing some optimization which is possible when incrementing the pointer by `coord_stride` in each iteration of the loop. However, this only affects bounds calculation and not the centroid calculation. - In C++, the STL iterator does a slightly better job optimizing `i * coord_stride` and in one case seems to do slightly better. This PR also adds "dimension iterators" `dbegin()` and `dend()` for iterating over a particular dimension. My personal takeaway is that except for possibly very cheap operations (like bounding, winding, and centroid calculations), C++ STL iteration is probably fine. A good reason to use dimension-specific iteration is if you are specifically aiming for autovectorization of some kind (or if you specifically are discarding values from another dimension).
- Loading branch information
1 parent
b926c18
commit db02936
Showing
9 changed files
with
509 additions
and
331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
#include <cmath> | ||
#include <cstdlib> | ||
|
||
namespace geoarrow { | ||
|
||
namespace benchmark_util { | ||
|
||
static const int64_t kNumCoordsPrettyBig = 10000000; | ||
|
||
static inline void PointsOnCircle(uint32_t n, uint32_t stride, double* out_x, | ||
double* out_y, double dangle_radians = M_PI / 100.0, | ||
double radius = 483.0) { | ||
double angle = 0; | ||
|
||
for (uint32_t i = 0; i < n; i++) { | ||
*out_x = std::cos(angle) * radius; | ||
*out_y = std::sin(angle) * radius; | ||
angle += dangle_radians; | ||
out_x += stride; | ||
out_y += stride; | ||
} | ||
} | ||
|
||
static inline void FillRandom(uint32_t n, uint32_t stride, double* out, | ||
uint32_t seed = 1234, double range_min = -1.0, | ||
double range_max = 1.0) { | ||
std::srand(seed); | ||
double range = range_max - range_max; | ||
for (uint32_t i = 0; i < n; i++) { | ||
double value01 = static_cast<double>(std::rand()) / static_cast<double>(RAND_MAX); | ||
*out = range_min + value01 * range; | ||
out += stride; | ||
} | ||
} | ||
|
||
} // namespace benchmark_util | ||
} // namespace geoarrow |
Oops, something went wrong.