Update benchmark library

1) In benchmark docs it says that a range-based loop is preferred
instead of KeepRunning() call:

  https://github.com/google/benchmark/blob/main/docs/user_guide.md#a-faster-keeprunning-loop

2) Now we call benchmark::Shutdown() in editor/view benchmarks exit
This commit is contained in:
David Capello 2024-12-05 20:13:37 -03:00
parent 890e27b0a1
commit 731e982a53
8 changed files with 25 additions and 22 deletions

View File

@ -43,7 +43,7 @@ void BM_ScrollEditor(benchmark::State& state) {
auto mgr = ui::Manager::getDefault();
mgr->dontWaitEvents();
while (state.KeepRunning()) {
for (auto _ : state) {
editor->setEditorScroll(gfx::Point(0, 0));
mgr->generateMessages();
mgr->dispatchMessages();
@ -70,7 +70,7 @@ void BM_ZoomEditor(benchmark::State& state) {
auto mgr = ui::Manager::getDefault();
mgr->dontWaitEvents();
while (state.KeepRunning()) {
for (auto _ : state) {
editor->setZoom(render::Zoom(4, 1));
editor->invalidate();
mgr->generateMessages();
@ -140,9 +140,10 @@ int app_main(int argc, char* argv[])
app.initialize(AppOptions(1, { argv2 }));
app.mainWindow()->expandWindow(gfx::Size(400, 300));
::benchmark::Initialize(&argc, argv);
int status = ::benchmark::RunSpecifiedBenchmarks();
benchmark::Initialize(&argc, argv);
benchmark::RunSpecifiedBenchmarks();
benchmark::Shutdown();
app.close();
return status;
return 0;
}

View File

@ -1,5 +1,5 @@
// Aseprite Document Library
// Copyright (c) 2023 Igara Studio S.A.
// Copyright (c) 2023-2024 Igara Studio S.A.
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -22,7 +22,7 @@ void BM_FlipSlow(benchmark::State& state) {
const int h = state.range(2);
const auto ft = (doc::algorithm::FlipType)state.range(3);
std::unique_ptr<Image> img(Image::create(pf, w, h));
while (state.KeepRunning()) {
for (auto _ : state) {
algorithm::flip_image_slow(img.get(), img->bounds(), ft);
}
}
@ -33,7 +33,7 @@ void BM_FlipRawPtr(benchmark::State& state) {
const int h = state.range(2);
const auto ft = (doc::algorithm::FlipType)state.range(3);
std::unique_ptr<Image> img(Image::create(pf, w, h));
while (state.KeepRunning()) {
for (auto _ : state) {
algorithm::flip_image(img.get(), img->bounds(), ft);
}
}

View File

@ -1,5 +1,5 @@
// Aseprite Document Library
// Copyright (c) 2019 Igara Studio S.A.
// Copyright (c) 2019-2024 Igara Studio S.A.
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -26,7 +26,7 @@ void BM_ShrinkBounds(benchmark::State& state) {
std::unique_ptr<Image> img(Image::create(pixelFormat, w, h));
img->putPixel(w/2, h/2, rgba(1, 2, 3, 4));
gfx::Rect rc;
while (state.KeepRunning()) {
for (auto _ : state) {
doc::algorithm::shrink_bounds(img.get(), 0, nullptr, rc);
}
}

View File

@ -1,4 +1,5 @@
// Aseprite Document Library
// Copyright (c) 2024 Igara Studio S.A.
// Copyright (c) 2017 David Capello
//
// This file is released under the terms of the MIT license.
@ -30,7 +31,7 @@ void BM_Rgba(benchmark::State& state) {
color_t b = color_t(state.range(1));
int opacity = state.range(2);
BlendFunc func = F;
while (state.KeepRunning()) {
for (auto _ : state) {
color_t c = func(a, b, opacity);
c = func(c, b, opacity);
}

View File

@ -1,5 +1,5 @@
// Aseprite Document Library
// Copyright (c) 2023 Igara Studio S.A.
// Copyright (c) 2023-2024 Igara Studio S.A.
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -24,7 +24,7 @@ void BM_IsSameImageOld(benchmark::State& state) {
ImageRef a(Image::create(pf, w, h));
doc::algorithm::random_image(a.get());
ImageRef b(Image::createCopy(a.get()));
while (state.KeepRunning()) {
for (auto _ : state) {
is_same_image_slow(a.get(), b.get());
}
}
@ -36,7 +36,7 @@ void BM_IsSameImageNew(benchmark::State& state) {
ImageRef a(Image::create(pf, w, h));
doc::algorithm::random_image(a.get());
ImageRef b(Image::createCopy(a.get()));
while (state.KeepRunning()) {
for (auto _ : state) {
is_same_image(a.get(), b.get());
}
}

View File

@ -1,5 +1,5 @@
// Aseprite Document Library
// Copyright (c) 2019-2022 Igara Studio S.A.
// Copyright (c) 2019-2024 Igara Studio S.A.
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -54,7 +54,7 @@ static void Bm_Render(benchmark::State& state)
std::unique_ptr<Image> dst(Image::create(spr->pixelFormat(), w, h));
clear_image(dst.get(), 0);
while (state.KeepRunning()) {
for (auto _ : state) {
clear_image(dst.get(), 0);
Render render;

View File

@ -28,7 +28,7 @@ void BM_ViewBase(benchmark::State& state) {
mgr->layout();
mgr->dontWaitEvents();
while (state.KeepRunning()) {
for (auto _ : state) {
// Do nothing case
mgr->generateMessages();
mgr->dispatchMessages();
@ -51,7 +51,7 @@ void BM_ViewScrollListBox(benchmark::State& state) {
const auto max = view->getScrollableSize();
int y = 0;
while (state.KeepRunning()) {
for (auto _ : state) {
view->setViewScroll(gfx::Point(0, y));
mgr->generateMessages();
mgr->dispatchMessages();
@ -89,8 +89,9 @@ int app_main(int argc, char* argv[])
window.addChild(g_view = new ui::View);
window.openWindow();
::benchmark::Initialize(&argc, argv);
int status = ::benchmark::RunSpecifiedBenchmarks();
benchmark::Initialize(&argc, argv);
benchmark::RunSpecifiedBenchmarks();
benchmark::Shutdown();
return status;
return 0;
}

@ -1 +1 @@
Subproject commit 02a354f3f323ae8256948e1dc77ddcb1dfc297da
Subproject commit c58e6d0710581e3a08d65c349664128a8d9a2461