Add {Source,CompositeCamera}Function benchmarks (#9838)

This commit is contained in:
Anand Thakker
2017-08-29 10:03:57 -04:00
committed by GitHub
parent a2712f6fa4
commit d436bcd56b
8 changed files with 265 additions and 3 deletions

View File

@@ -108,7 +108,7 @@ run-test-%: test
run-benchmark: run-benchmark-.
run-benchmark-%: benchmark
$(MACOS_OUTPUT_PATH)/$(BUILDTYPE)/mbgl-benchmark --benchmark_filter=$*
$(MACOS_OUTPUT_PATH)/$(BUILDTYPE)/mbgl-benchmark --benchmark_filter=$* ${BENCHMARK_ARGS}
.PHONY: node-benchmark
node-benchmark: $(MACOS_PROJ_PATH)

View File

@@ -0,0 +1,69 @@
#include <benchmark/benchmark.h>
#include <mbgl/style/function/source_function.hpp>
#include <mbgl/style/rapidjson_conversion.hpp>
#include <mbgl/style/conversion.hpp>
#include <mbgl/style/conversion/function.hpp>
#include <rapidjson/document.h>
using namespace mbgl;
using namespace mbgl::style;
static rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> createFunctionJSON(size_t stopCount) {
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> doc;
std::string stops = "[";
for (size_t i = 0; i < stopCount; i++) {
std::string value = std::to_string(24.0f / stopCount * i);
if (stops.size() > 1) stops += ",";
stops += "[" + value + ", " + value + "]";
}
stops += "]";
doc.Parse<0>(R"({"type": "exponential", "base": 2, "stops": )" + stops + "}");
return doc;
}
static void Parse_CameraFunction(benchmark::State& state) {
size_t stopCount = state.range(0);
while (state.KeepRunning()) {
conversion::Error error;
state.PauseTiming();
auto doc = createFunctionJSON(stopCount);
state.ResumeTiming();
optional<CameraFunction<float>> result = conversion::convert<CameraFunction<float>, JSValue>(doc, error);
if (!result) {
state.SkipWithError(error.message.c_str());
}
}
state.SetLabel(std::to_string(stopCount).c_str());
}
static void Evaluate_CameraFunction(benchmark::State& state) {
size_t stopCount = state.range(0);
auto doc = createFunctionJSON(stopCount);
conversion::Error error;
optional<CameraFunction<float>> function = conversion::convert<CameraFunction<float>, JSValue>(doc, error);
if (!function) {
state.SkipWithError(error.message.c_str());
}
while(state.KeepRunning()) {
float z = 24.0f * static_cast<float>(rand() % 100) / 100;
function->evaluate(z);
}
state.SetLabel(std::to_string(stopCount).c_str());
}
BENCHMARK(Parse_CameraFunction)
->Arg(1)->Arg(2)->Arg(4)->Arg(6)->Arg(8)->Arg(10)->Arg(12);
BENCHMARK(Evaluate_CameraFunction)
->Arg(1)->Arg(2)->Arg(4)->Arg(6)->Arg(8)->Arg(10)->Arg(12);

View File

@@ -0,0 +1,76 @@
#include <benchmark/benchmark.h>
#include <mbgl/benchmark/stub_geometry_tile_feature.hpp>
#include <mbgl/style/function/composite_exponential_stops.hpp>
#include <mbgl/style/function/composite_function.hpp>
#include <mbgl/style/rapidjson_conversion.hpp>
#include <mbgl/style/conversion.hpp>
#include <mbgl/style/conversion/function.hpp>
#include <rapidjson/document.h>
using namespace mbgl;
using namespace mbgl::style;
static rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> createFunctionJSON(size_t stopCount) {
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> doc;
std::string stops = "[";
for (size_t outerStop = 0; outerStop < stopCount; outerStop++) {
for (size_t innerStop = 0; innerStop < stopCount; innerStop++) {
std::string zoom = std::to_string(24.0f / stopCount * outerStop);
std::string value = std::to_string(100.0f / stopCount * innerStop);
if (stops.size() > 1) stops += ",";
stops += R"([{"zoom":)" + zoom + R"(,"value":)" + value + "}, " + value + "]";
}
}
stops += "]";
doc.Parse<0>(R"({"type": "exponential", "base": 2, "stops": )" + stops + R"(, "property": "x"})");
return doc;
}
static void Parse_CompositeFunction(benchmark::State& state) {
size_t stopCount = state.range(0);
while (state.KeepRunning()) {
conversion::Error error;
state.PauseTiming();
auto doc = createFunctionJSON(stopCount);
state.ResumeTiming();
optional<CompositeFunction<float>> result = conversion::convert<style::CompositeFunction<float>, JSValue>(doc, error);
if (!result) {
state.SkipWithError(error.message.c_str());
}
}
state.SetLabel(std::to_string(stopCount).c_str());
}
static void Evaluate_CompositeFunction(benchmark::State& state) {
size_t stopCount = state.range(0);
auto doc = createFunctionJSON(stopCount);
conversion::Error error;
optional<CompositeFunction<float>> function = conversion::convert<CompositeFunction<float>, JSValue>(doc, error);
if (!function) {
state.SkipWithError(error.message.c_str());
}
while(state.KeepRunning()) {
float z = 24.0f * static_cast<float>(rand() % 100) / 100;
function->evaluate(z, StubGeometryTileFeature(PropertyMap { { "x", static_cast<int64_t>(rand() % 100) } }), -1.0f);
}
state.SetLabel(std::to_string(stopCount).c_str());
}
BENCHMARK(Parse_CompositeFunction)
->Arg(1)->Arg(2)->Arg(4)->Arg(6)->Arg(8)->Arg(10)->Arg(12);
BENCHMARK(Evaluate_CompositeFunction)
->Arg(1)->Arg(2)->Arg(4)->Arg(6)->Arg(8)->Arg(10)->Arg(12);

View File

@@ -0,0 +1,70 @@
#include <benchmark/benchmark.h>
#include <mbgl/benchmark/stub_geometry_tile_feature.hpp>
#include <mbgl/style/function/source_function.hpp>
#include <mbgl/style/rapidjson_conversion.hpp>
#include <mbgl/style/conversion.hpp>
#include <mbgl/style/conversion/function.hpp>
#include <rapidjson/document.h>
using namespace mbgl;
using namespace mbgl::style;
static rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> createFunctionJSON(size_t stopCount) {
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> doc;
std::string stops = "[";
for (size_t i = 0; i < stopCount; i++) {
std::string value = std::to_string(100.0f / stopCount * i);
if (stops.size() > 1) stops += ",";
stops += "[" + value + ", " + value + "]";
}
stops += "]";
doc.Parse<0>(R"({"type": "exponential", "base": 2, "stops": )" + stops + R"(, "property": "x"})");
return doc;
}
static void Parse_SourceFunction(benchmark::State& state) {
size_t stopCount = state.range(0);
while (state.KeepRunning()) {
conversion::Error error;
state.PauseTiming();
auto doc = createFunctionJSON(stopCount);
state.ResumeTiming();
optional<SourceFunction<float>> result = conversion::convert<SourceFunction<float>, JSValue>(doc, error);
if (!result) {
state.SkipWithError(error.message.c_str());
}
}
state.SetLabel(std::to_string(stopCount).c_str());
}
static void Evaluate_SourceFunction(benchmark::State& state) {
size_t stopCount = state.range(0);
auto doc = createFunctionJSON(stopCount);
conversion::Error error;
optional<SourceFunction<float>> function = conversion::convert<SourceFunction<float>, JSValue>(doc, error);
if (!function) {
state.SkipWithError(error.message.c_str());
}
while(state.KeepRunning()) {
function->evaluate(StubGeometryTileFeature(PropertyMap { { "x", static_cast<int64_t>(rand() % 100) } }), -1.0f);
}
state.SetLabel(std::to_string(stopCount).c_str());
}
BENCHMARK(Parse_SourceFunction)
->Arg(1)->Arg(2)->Arg(4)->Arg(6)->Arg(8)->Arg(10)->Arg(12);
BENCHMARK(Evaluate_SourceFunction)
->Arg(1)->Arg(2)->Arg(4)->Arg(6)->Arg(8)->Arg(10)->Arg(12);

View File

@@ -0,0 +1,41 @@
#pragma once
#include <mbgl/tile/geometry_tile_data.hpp>
#include <mbgl/util/feature.hpp>
using namespace mbgl;
class StubGeometryTileFeature : public GeometryTileFeature {
public:
StubGeometryTileFeature(PropertyMap properties_)
: properties(std::move(properties_)) {
}
StubGeometryTileFeature(optional<FeatureIdentifier> id_, FeatureType type_, GeometryCollection geometry_, PropertyMap properties_)
: properties(std::move(properties_)),
id(std::move(id_)),
type(type_),
geometry(std::move(geometry_)) {
}
PropertyMap properties;
optional<FeatureIdentifier> id;
FeatureType type = FeatureType::Point;
GeometryCollection geometry;
FeatureType getType() const override {
return type;
}
optional<FeatureIdentifier> getID() const override {
return id;
}
optional<Value> getValue(const std::string& key) const override {
return properties.count(key) ? properties.at(key) : optional<Value>();
}
GeometryCollection getGeometries() const override {
return geometry;
}
};

View File

@@ -5,6 +5,11 @@ set(MBGL_BENCHMARK_FILES
benchmark/api/query.benchmark.cpp
benchmark/api/render.benchmark.cpp
# function
benchmark/function/camera_function.benchmark.cpp
benchmark/function/composite_function.benchmark.cpp
benchmark/function/source_function.benchmark.cpp
# include/mbgl
benchmark/include/mbgl/benchmark.hpp
@@ -18,6 +23,7 @@ set(MBGL_BENCHMARK_FILES
# src/mbgl/benchmark
benchmark/src/mbgl/benchmark/benchmark.cpp
benchmark/src/mbgl/benchmark/stub_geometry_tile_feature.hpp
# util
benchmark/util/dtoa.benchmark.cpp

View File

@@ -8,7 +8,7 @@ mason_use(libpng VERSION 1.6.25)
mason_use(libjpeg-turbo VERSION 1.5.0)
mason_use(webp VERSION 0.5.1)
mason_use(gtest VERSION 1.8.0${MASON_CXXABI_SUFFIX})
mason_use(benchmark VERSION 1.0.0-1)
mason_use(benchmark VERSION 1.2.0)
mason_use(icu VERSION 58.1-min-size)
# Link with libuv. This is not part of loop-uv.cmake because loop-uv.cmake is also

View File

@@ -3,7 +3,7 @@ set(CMAKE_OSX_DEPLOYMENT_TARGET 10.10)
mason_use(glfw VERSION 2017-07-13-67c9155)
mason_use(boost_libprogram_options VERSION 1.62.0)
mason_use(gtest VERSION 1.8.0)
mason_use(benchmark VERSION 1.0.0-1)
mason_use(benchmark VERSION 1.2.0)
mason_use(icu VERSION 58.1-min-size)
include(cmake/loop-darwin.cmake)