forked from OSGeo/shapelib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run benchmark on SHPSetFastModeReadObject
- Loading branch information
Showing
3 changed files
with
63 additions
and
3 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 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 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,42 @@ | ||
#include <filesystem> | ||
|
||
#include <benchmark/benchmark.h> | ||
#include "shapefil.h" | ||
|
||
namespace fs = std::filesystem; | ||
|
||
namespace | ||
{ | ||
|
||
static const auto kTestData = fs::path{"shape_eg_data"}; | ||
|
||
template <bool fastMode> static void Benchmark_ReadAll(benchmark::State &state) | ||
{ | ||
for (auto _ : state) | ||
{ | ||
const auto filename = kTestData / "mpatch3.shp"; | ||
const auto handle = SHPOpen(filename.string().c_str(), "rb"); | ||
if constexpr (fastMode) | ||
{ | ||
SHPSetFastModeReadObject(handle, 1); | ||
} | ||
int nEntities; | ||
SHPGetInfo(handle, &nEntities, nullptr, nullptr, nullptr); | ||
for (int i = 0; i < nEntities; ++i) | ||
{ | ||
auto obj = SHPReadObject(handle, i); | ||
SHPDestroyObject(obj); | ||
} | ||
SHPClose(handle); | ||
} | ||
} | ||
|
||
constexpr auto Benchmark_ReadAllSlow = Benchmark_ReadAll<false>; | ||
constexpr auto Benchmark_ReadAllFast = Benchmark_ReadAll<true>; | ||
|
||
BENCHMARK(Benchmark_ReadAllSlow); | ||
BENCHMARK(Benchmark_ReadAllFast); | ||
|
||
} // namespace | ||
|
||
BENCHMARK_MAIN(); |