From 3162d224f72220d75cd47d2477c5e248f57c04c3 Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 21 Feb 2022 10:28:10 -0300 Subject: [PATCH] Add editor_benchmark This is a simple initial benchmark to test how well the editor perform in common operations like scroll and zoom. We have plans to improve it through caching (and GPU textures) progressively. --- src/CMakeLists.txt | 3 +- src/app/app.cpp | 7 +- src/app/app.h | 1 + src/app/editor_benchmark.cpp | 148 +++++++++++++++++++++++++++++++++++ 4 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 src/app/editor_benchmark.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 12ddf202d..42edbc752 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,5 @@ # Aseprite -# Copyright (C) 2019-2020 Igara Studio S.A. +# Copyright (C) 2019-2022 Igara Studio S.A. # Copyright (C) 2001-2018 David Capello ###################################################################### @@ -227,6 +227,7 @@ endif() if(ENABLE_BENCHMARKS) include(FindBenchmarks) + find_benchmarks(app app-lib) find_benchmarks(doc doc-lib) find_benchmarks(doc/algorithm doc-lib) find_benchmarks(render render-lib) diff --git a/src/app/app.cpp b/src/app/app.cpp index 507de6dbd..783dbb827 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2021 Igara Studio S.A. +// Copyright (C) 2018-2022 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -462,6 +462,11 @@ void App::run() extensions().executeExitActions(); #endif + close(); +} + +void App::close() +{ #ifdef ENABLE_UI if (isGui()) { // Select no document diff --git a/src/app/app.h b/src/app/app.h index e178ee519..057f1ffc0 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -86,6 +86,7 @@ namespace app { // scripts. int initialize(const AppOptions& options); void run(); + void close(); AppMod* mod() const { return m_mod; } tools::ToolBox* toolBox() const; diff --git a/src/app/editor_benchmark.cpp b/src/app/editor_benchmark.cpp new file mode 100644 index 000000000..3102a9842 --- /dev/null +++ b/src/app/editor_benchmark.cpp @@ -0,0 +1,148 @@ +// Aseprite +// Copyright (C) 2022 Igara Studio S.A. +// +// This program is distributed under the terms of +// the End-User License Agreement for Aseprite. + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "app/app.h" +#include "app/cli/app_options.h" +#include "app/doc.h" +#include "app/ui/editor/editor.h" +#include "app/ui/main_window.h" +#include "app/ui_context.h" +#include "doc/sprite.h" +#include "os/system.h" +#include "ui/manager.h" +#include "ui/system.h" +#include "ui/timer.h" + +#include + +using namespace app; +using namespace doc; + +void BM_ScrollEditor(benchmark::State& state) { + const int w = state.range(0); + const int h = state.range(1); + const int zNum = state.range(2); + const int zDen = state.range(3); + auto ctx = UIContext::instance(); + + Sprite* spr = new Sprite(ImageSpec(ColorMode::RGB, w, h), 256); + std::unique_ptr doc(new Doc(spr)); + doc->setContext(ctx); + + Editor* editor = ctx->activeEditor(); + editor->setZoom(render::Zoom(zNum, zDen)); + + auto mgr = ui::Manager::getDefault(); + + ui::Timer timer(1); + timer.start(); + while (state.KeepRunning()) { + editor->setEditorScroll(gfx::Point(0, 0)); + mgr->generateMessages(); + mgr->dispatchMessages(); + + editor->setEditorScroll(gfx::Point(100, 100)); + mgr->generateMessages(); + mgr->dispatchMessages(); + } +} + +void BM_ZoomEditor(benchmark::State& state) { + const int w = state.range(0); + const int h = state.range(1); + auto ctx = UIContext::instance(); + + Sprite* spr = new Sprite(ImageSpec(ColorMode::RGB, w, h), 256); + std::unique_ptr doc(new Doc(spr)); + doc->setContext(ctx); + + Editor* editor = ctx->activeEditor(); + editor->setZoom(render::Zoom(1, 1)); + editor->setScrollToCenter(); + + auto mgr = ui::Manager::getDefault(); + + ui::Timer timer(1); + timer.start(); + while (state.KeepRunning()) { + editor->setZoom(render::Zoom(4, 1)); + editor->invalidate(); + mgr->generateMessages(); + mgr->dispatchMessages(); + + editor->setZoom(render::Zoom(2, 1)); + editor->invalidate(); + mgr->generateMessages(); + mgr->dispatchMessages(); + + editor->setZoom(render::Zoom(1, 1)); + editor->invalidate(); + mgr->generateMessages(); + mgr->dispatchMessages(); + + editor->setZoom(render::Zoom(1, 2)); + editor->invalidate(); + mgr->generateMessages(); + mgr->dispatchMessages(); + + editor->setZoom(render::Zoom(1, 4)); + editor->invalidate(); + mgr->generateMessages(); + mgr->dispatchMessages(); + } +} + +BENCHMARK(BM_ScrollEditor) + // Normal zoom + ->Args({ 32, 32, 1, 1 }) + ->Args({ 256, 256, 1, 1 }) + ->Args({ 1024, 1024, 1, 1 }) + ->Args({ 4096, 4096, 1, 1 }) + // Zoom in + ->Args({ 32, 32, 2, 1 }) + ->Args({ 256, 256, 2, 1 }) + ->Args({ 1024, 1024, 2, 1 }) + ->Args({ 4096, 4096, 2, 1 }) + ->Args({ 32, 32, 4, 1 }) + ->Args({ 256, 256, 4, 1 }) + ->Args({ 1024, 1024, 4, 1 }) + ->Args({ 4096, 4096, 4, 1 }) + // Zoom out + ->Args({ 32, 32, 1, 2 }) + ->Args({ 256, 256, 1, 2 }) + ->Args({ 1024, 1024, 1, 2 }) + ->Args({ 4096, 4096, 1, 2 }) + ->Args({ 32, 32, 1, 4 }) + ->Args({ 256, 256, 1, 4 }) + ->Args({ 1024, 1024, 1, 4 }) + ->Args({ 4096, 4096, 1, 4 }) + ->Unit(benchmark::kMicrosecond); + +BENCHMARK(BM_ZoomEditor) + ->Args({ 32, 32 }) + ->Args({ 256, 256 }) + ->Args({ 1024, 1024 }) + ->Args({ 4096, 4096 }) + ->Unit(benchmark::kMicrosecond); + +int app_main(int argc, char* argv[]) +{ + os::SystemRef system(os::make_system()); + App app; + const char* argv2[] = { argv[0] }; + app.initialize(AppOptions(1, { argv2 })); + app.mainWindow()->expandWindow(gfx::Size(400, 300)); + + ::benchmark::Initialize(&argc, argv); + int status = ::benchmark::RunSpecifiedBenchmarks(); + + app.close(); + return status; +}