Skip to content

Commit

Permalink
Use google benchmarks and fix minor performance issues (mapbox#91)
Browse files Browse the repository at this point in the history
* Convert benchmarks to google benchmark

* Reserve container sizes and emplace elements

* Update xcode version for macOS bot

* Don't copy properties during index generation

* Move clipped rings
  • Loading branch information
alexshalamov committed Aug 11, 2020
1 parent 32020bd commit 1c0e989
Show file tree
Hide file tree
Showing 9 changed files with 136,545 additions and 125 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ matrix:
sources: [ 'ubuntu-toolchain-r-test', ]
packages: [ 'libstdc++-5-dev', 'libxi-dev','libglu1-mesa-dev','x11proto-randr-dev','x11proto-xext-dev','libxrandr-dev','x11proto-xf86vidmode-dev','libxxf86vm-dev','libxcursor-dev','libxinerama-dev']
- os: osx
osx_image: xcode7.3
osx_image: xcode12
env: BUILDTYPE=Release

cache: apt
Expand Down
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CXXFLAGS += -I include -std=c++14 -Wall -Wextra -D_GLIBCXX_USE_CXX11_ABI=0
RELEASE_FLAGS ?= -O3 -DNDEBUG
RELEASE_FLAGS ?= -O3 -DNDEBUG -g -ggdb3
DEBUG_FLAGS ?= -g -O0 -DDEBUG

MASON ?= .mason/mason
Expand All @@ -10,6 +10,7 @@ GEOJSON = geojson 0.4.3
GLFW = glfw 3.1.2
GTEST = gtest 1.8.0
RAPIDJSON = rapidjson 1.1.0
BENCHMARK = benchmark 1.4.1

VARIANT_FLAGS = `$(MASON) cflags $(VARIANT)`
GEOMETRY_FLAGS = `$(MASON) cflags $(GEOMETRY)`
Expand All @@ -18,6 +19,7 @@ GLFW_FLAGS = `$(MASON) cflags $(GLFW)` `$(MASON) static_libs $(GLFW)` `$(MASON)
GTEST_FLAGS = `$(MASON) cflags $(GTEST)` `$(MASON) static_libs $(GTEST)` `$(MASON) ldflags $(GTEST)`
RAPIDJSON_FLAGS = `$(MASON) cflags $(RAPIDJSON)`
BASE_FLAGS = $(VARIANT_FLAGS) $(GEOMETRY_FLAGS) $(GEOJSON_FLAGS)
BENCHMARK_FLAGS = `$(MASON) cflags $(BENCHMARK)` `$(MASON) static_libs $(BENCHMARK)` `$(MASON) ldflags $(BENCHMARK)`

DEPS = mason_packages/headers/geometry include/mapbox/geojsonvt/*.hpp include/mapbox/geojsonvt.hpp bench/util.hpp Makefile

Expand All @@ -30,12 +32,13 @@ mason_packages/headers/geometry: Makefile
$(MASON) install $(GLFW)
$(MASON) install $(GTEST)
$(MASON) install $(RAPIDJSON)
$(MASON) install $(BENCHMARK)

build:
mkdir -p build

build/bench: build bench/run.cpp $(DEPS)
$(CXX) $(CFLAGS) $(CXXFLAGS) $(RELEASE_FLAGS) bench/run.cpp -o build/bench $(BASE_FLAGS) $(RAPIDJSON_FLAGS)
build/bench: build bench/main.cpp bench/benchmark.cpp $(DEPS)
$(CXX) $(CFLAGS) $(CXXFLAGS) $(RELEASE_FLAGS) bench/main.cpp bench/benchmark.cpp -o build/bench $(BASE_FLAGS) $(RAPIDJSON_FLAGS) $(BENCHMARK_FLAGS)

build/debug: build debug/debug.cpp $(DEPS)
$(CXX) $(CFLAGS) $(CXXFLAGS) $(DEBUG_FLAGS) debug/debug.cpp -o build/debug $(BASE_FLAGS) $(GLFW_FLAGS) $(RAPIDJSON_FLAGS)
Expand Down
110 changes: 110 additions & 0 deletions bench/benchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#include <benchmark/benchmark.h>
#include <mapbox/geojson.hpp>
#include <mapbox/geojson_impl.hpp>
#include <mapbox/geojsonvt.hpp>

#include "util.hpp"

static void ParseGeoJSON(::benchmark::State& state) {
const std::string json = loadFile("data/countries.geojson");
for (auto _ : state) {
mapbox::geojson::parse(json).get<mapbox::geojson::feature_collection>();
}
}
BENCHMARK(ParseGeoJSON)->Unit(benchmark::kMicrosecond);

static void GenerateTileIndex(::benchmark::State& state) {
const std::string json = loadFile("data/countries.geojson");
const auto features = mapbox::geojson::parse(json).get<mapbox::geojson::feature_collection>();
mapbox::geojsonvt::Options options;
options.indexMaxZoom = 7;
options.indexMaxPoints = 200;

for (auto _ : state) {
mapbox::geojsonvt::GeoJSONVT index{ features, options };
(void)index;
}
}
BENCHMARK(GenerateTileIndex)->Unit(benchmark::kMicrosecond);

static void TraverseTilePyramid(::benchmark::State& state) {
const std::string json = loadFile("data/countries.geojson");
const auto features = mapbox::geojson::parse(json).get<mapbox::geojson::feature_collection>();
mapbox::geojsonvt::Options options;
options.indexMaxZoom = 7;
options.indexMaxPoints = 200;
mapbox::geojsonvt::GeoJSONVT index{ features, options };

for (auto _ : state) {
const unsigned max_z = 11;
for (unsigned z = 0; z < max_z; ++z) {
unsigned num_tiles = std::pow(2, z);
for (unsigned x = 0; x < num_tiles; ++x) {
for (unsigned y = 0; y < num_tiles; ++y) {
index.getTile(z, x, y);
}
}
}
}
}
BENCHMARK(TraverseTilePyramid)->Unit(benchmark::kMillisecond)->Iterations(3);

static void LargeGeoJSONParse(::benchmark::State& state) {
const std::string json = loadFile("test/fixtures/points.geojson");
for (auto _ : state) {
mapbox::geojson::parse(json).get<mapbox::geojson::feature_collection>();
}
}
BENCHMARK(LargeGeoJSONParse)->Unit(benchmark::kMicrosecond);

static void LargeGeoJSONTileIndex(::benchmark::State& state) {
const std::string json = loadFile("test/fixtures/points.geojson");
const auto features = mapbox::geojson::parse(json).get<mapbox::geojson::feature_collection>();
mapbox::geojsonvt::Options options;
for (auto _ : state) {
mapbox::geojsonvt::GeoJSONVT index{ features, options };
}
}
BENCHMARK(LargeGeoJSONTileIndex)->Unit(benchmark::kMicrosecond);

static void LargeGeoJSONGetTile(::benchmark::State& state) {
const std::string json = loadFile("test/fixtures/points.geojson");
const auto features = mapbox::geojson::parse(json).get<mapbox::geojson::feature_collection>();
mapbox::geojsonvt::Options options;
mapbox::geojsonvt::GeoJSONVT index{ features, options };
for (auto _ : state) {
index.getTile(12, 1171, 1566);
}
}
BENCHMARK(LargeGeoJSONGetTile)->Unit(benchmark::kMillisecond)->Iterations(1)->Repetitions(9)->ReportAggregatesOnly(true);

static void LargeGeoJSONToTile(::benchmark::State& state) {
const std::string json = loadFile("data/countries.geojson");
const auto features = mapbox::geojson::parse(json).get<mapbox::geojson::feature_collection>();
for (auto _ : state) {
mapbox::geojsonvt::geoJSONToTile(features, 12, 1171, 1566, {}, false, true);
}
}
BENCHMARK(LargeGeoJSONToTile)->Unit(benchmark::kMicrosecond);

static void SingleTileIndex(::benchmark::State& state) {
const std::string json = loadFile("test/fixtures/single-tile.json");
const auto features = mapbox::geojson::parse(json);
mapbox::geojsonvt::Options options;
options.indexMaxZoom = 7;
options.indexMaxPoints = 10000;
mapbox::geojsonvt::GeoJSONVT index{ features, options };
for (auto _ : state) {
index.getTile(12, 1171, 1566);
}
}
BENCHMARK(SingleTileIndex)->Unit(benchmark::kMicrosecond);

static void SingleTileGeoJSONToTile(::benchmark::State& state) {
const std::string json = loadFile("test/fixtures/single-tile.json");
const auto features = mapbox::geojson::parse(json);
for (auto _ : state) {
mapbox::geojsonvt::geoJSONToTile(features, 12, 1171, 1566, {}, false, true);
}
}
BENCHMARK(SingleTileGeoJSONToTile)->Unit(benchmark::kMicrosecond);
7 changes: 7 additions & 0 deletions bench/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <benchmark/benchmark.h>

int main(int argc, char* argv[]) {
::benchmark::Initialize(&argc, argv);
::benchmark::RunSpecifiedBenchmarks();
return 0;
}
67 changes: 0 additions & 67 deletions bench/run.cpp

This file was deleted.

Loading

0 comments on commit 1c0e989

Please sign in to comment.