iOS moving camera benchmark (#2076)

Co-authored-by: Bart Louwers <bart@emeel.net>
This commit is contained in:
Alex Cristici
2024-02-01 20:53:28 +02:00
committed by GitHub
parent 867e7cc813
commit b683cceb3f
2 changed files with 32 additions and 37 deletions

View File

@@ -31,7 +31,7 @@ public:
//NSLog(@"Frame rendering time: %4.1f ms", status.frameRenderingTime * 1e3);
bool fullyRendered = status.mode == mbgl::MapObserver::RenderMode::Full;
[mapDelegate mapDidFinishRenderingFrameFullyRendered:fullyRendered
[mapDelegate mapDidFinishRenderingFrameFullyRendered:fullyRendered
frameEncodingTime:status.frameEncodingTime
frameRenderingTime:status.frameRenderingTime];
}
@@ -176,15 +176,14 @@ NSDate* const currentDate = [NSDate date];
}
size_t idx = 0;
enum class State { None, WaitingForAssets, WarmingUp, Benchmarking } state = State::None;
enum class State { None, WaitingForAssets, Benchmarking } state = State::None;
int frames = 0;
double totalFrameEncodingTime = 0;
double totalFrameRenderingTime = 0;
std::chrono::steady_clock::time_point started;
std::vector<std::pair<std::string, std::pair<double, double>> > result;
static const int warmupDuration = 20; // frames
static const int benchmarkDuration = 200; // frames
static const int benchmarkDuration = 5; // seconds
namespace mbgl {
extern std::size_t uploadCount, uploadBuildCount, uploadVertextAttrsDirty, uploadInvalidSegments;
@@ -225,7 +224,9 @@ namespace mbgl {
cameraOptions.center = mbgl::LatLng(location.latitude, location.longitude);
cameraOptions.zoom = location.zoom;
cameraOptions.bearing = location.bearing;
map->jumpTo(cameraOptions);
mbgl::AnimationOptions animationOptions;
animationOptions.duration.emplace(std::chrono::duration_cast<mbgl::Duration>(std::chrono::duration<NSTimeInterval>(benchmarkDuration)));
map->easeTo(cameraOptions, animationOptions);
state = State::WaitingForAssets;
NSLog(@"Benchmarking \"%s\"", location.name.c_str());
@@ -293,17 +294,17 @@ namespace mbgl {
frames++;
totalFrameEncodingTime += frameEncodingTime;
totalFrameRenderingTime += frameRenderingTime;
if (frames >= benchmarkDuration)
const auto duration = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - started).count();
if (duration >= benchmarkDuration * 1e6)
{
state = State::None;
// Report FPS
const auto duration = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now() - started).count();
const auto wallClockFPS = double(frames * 1e6) / duration;
const auto frameEncodingTime = static_cast<double>(totalFrameEncodingTime) / frames;
const auto frameRenderingTime = static_cast<double>(totalFrameRenderingTime) / frames;
result.emplace_back(mbgl::bench::locations[idx].name, std::make_pair(frameEncodingTime, frameRenderingTime));
NSLog(@"- Frame encoding time: %.1f ms, Frame rendering time: %.1f ms (%.1f sync FPS)", frameEncodingTime * 1e3, frameRenderingTime * 1e3, wallClockFPS);
NSLog(@"- Frame encoding time: %.1f ms, Frame rendering time: %.1f ms (%d frames)", frameEncodingTime * 1e3, frameRenderingTime * 1e3, frames);
// Start benchmarking the next location.
idx++;
@@ -315,30 +316,17 @@ namespace mbgl {
}
return;
}
else if (state == State::WarmingUp)
{
frames++;
if (frames >= warmupDuration)
{
frames = 0;
totalFrameEncodingTime = 0;
totalFrameRenderingTime = 0;
state = State::Benchmarking;
started = std::chrono::steady_clock::now();
NSLog(@"- Benchmarking for %d frames...", benchmarkDuration);
}
dispatch_async(dispatch_get_main_queue(), ^{
[self renderFrame];
});
return;
}
else if (state == State::WaitingForAssets)
{
if (map->isFullyLoaded())
{
// Start the benchmarking timer.
state = State::WarmingUp;
NSLog(@"- Warming up for %d frames...", warmupDuration);
frames = 0;
totalFrameEncodingTime = 0;
totalFrameRenderingTime = 0;
state = State::Benchmarking;
started = std::chrono::steady_clock::now();
NSLog(@"- Benchmarking for %d seconds...", benchmarkDuration);
}
dispatch_async(dispatch_get_main_queue(), ^{
[self renderFrame];

View File

@@ -4,15 +4,22 @@ namespace mbgl {
namespace bench {
const std::vector<Location> locations = {
{ "boston", -71.07766, 42.36513, 16, 0.0 },
{ "paris", 2.3411, 48.8664, 11, 0.0 },
{ "paris2", 2.3516, 48.8356, 13, 273.8 },
{ "alps", 10.6107, 46.9599, 6, 0.0 },
{ "us east", -84.3395, 36.9400, 5, 0.0 },
{ "greater la", -117.9529, 34.0259, 9, 0.0 },
{ "sf", -122.4202, 37.7625, 14, 0.0 },
{ "oakland", -122.2328, 37.8267, 12, 0.0 },
{ "germany", 9.2280, 50.9262, 6, 0.0 },
{ "SF zoom in", -122.4194, 37.7749, 14, 0.0 },
{ "SF zoom out", -122.4194, 37.7749, 2, 0.0 },
{ "DC zoom in", -77.0369, 38.9072, 14, 0.0 },
{ "DC zoom out", -77.0369, 38.9072, 2, 0.0 },
{ "AMS zoom in", 4.8952, 52.3702, 14, 0.0 },
{ "AMS zoom out", 4.8952, 52.3702, 2, 0.0 },
{ "HEL zoom in", 24.9384, 60.1699, 14, 0.0 },
{ "HEL zoom out", 24.9384, 60.1699, 2, 0.0 },
{ "AYA zoom in", -74.2236, -13.1639, 14, 0.0 },
{ "AYA zoom out", -74.2236, -13.1639, 2, 0.0 },
{ "BER zoom in", 13.4050, 52.5200, 14, 0.0 },
{ "BER zoom out", 13.4050, 52.5200, 2, 0.0 },
{ "BAN zoom in", 77.5946, 12.9716, 14, 0.0 },
{ "BAN zoom out", 77.5946, 12.9716, 2, 0.0 },
{ "SHA zoom in", 121.4737, 31.2304, 14, 0.0 },
{ "SHA zoom out", 121.4737, 31.2304, 2, 0.0 },
};
}