Add some simple benchmarks for color blending functions

This commit is contained in:
David Capello 2017-07-18 17:03:12 -03:00
parent 85bd973834
commit 7cbf5fd420
7 changed files with 116 additions and 2 deletions

3
.gitmodules vendored
View File

@ -51,3 +51,6 @@
[submodule "third_party/json11"]
path = third_party/json11
url = https://github.com/aseprite/json11.git
[submodule "third_party/benchmark"]
path = third_party/benchmark
url = https://github.com/aseprite/benchmark.git

View File

@ -73,7 +73,8 @@ option(ENABLE_MEMLEAK "Enable memory-leaks detector (only for developers)" o
option(ENABLE_UPDATER "Enable automatic check for updates" on)
option(ENABLE_SCRIPTING "Compile with scripting support" on)
option(ENABLE_WEBSERVER "Enable support to run a webserver (for HTML5 gamedev)" off)
option(ENABLE_TESTS "Enable the unit tests" off)
option(ENABLE_TESTS "Compile unit tests" off)
option(ENABLE_BENCHMARKS "Compile benchmarks" off)
option(ENABLE_TRIAL_MODE "Compile the trial version" off)
option(ENABLE_STEAM "Compile with Steam library" off)
option(FULLSCREEN_PLATFORM "Enable fullscreen by default" off)

View File

@ -0,0 +1,26 @@
# Copyright (C) 2017 David Capello
# Find benchmarks
function(find_benchmarks dir dependencies)
file(GLOB benchmarks ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*_benchmark.cpp)
list(REMOVE_AT ARGV 0)
foreach(benchmarksourcefile ${benchmarks})
get_filename_component(benchmarkname ${benchmarksourcefile} NAME_WE)
add_executable(${benchmarkname} ${benchmarksourcefile})
if(MSVC)
# Fix problem compiling gen from a Visual Studio solution
set_target_properties(${benchmarkname}
PROPERTIES LINK_FLAGS -ENTRY:"mainCRTStartup")
endif()
target_link_libraries(${benchmarkname} benchmark ${ARGV} ${PLATFORM_LIBS})
if(extra_definitions)
set_target_properties(${benchmarkname}
PROPERTIES COMPILE_FLAGS ${extra_definitions})
endif()
endforeach()
endfunction()

View File

@ -189,7 +189,6 @@ install(DIRECTORY ../data
if(ENABLE_TESTS)
include(FindTests)
find_tests(gfx gfx-lib)
find_tests(doc doc-lib)
find_tests(render render-lib)
@ -199,3 +198,8 @@ if(ENABLE_TESTS)
find_tests(app app-lib)
find_tests(. app-lib)
endif()
if(ENABLE_BENCHMARKS)
include(FindBenchmarks)
find_benchmarks(doc doc-lib)
endif()

View File

@ -0,0 +1,74 @@
// Aseprite Document Library
// Copyright (c) 2017 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "doc/blend_funcs.h"
#include <benchmark/benchmark.h>
namespace doc {
color_t rgba_blender_multiply(color_t backdrop, color_t src, int opacity);
color_t rgba_blender_screen(color_t backdrop, color_t src, int opacity);
color_t rgba_blender_overlay(color_t backdrop, color_t src, int opacity);
color_t rgba_blender_darken(color_t backdrop, color_t src, int opacity);
color_t rgba_blender_lighten(color_t backdrop, color_t src, int opacity);
color_t rgba_blender_color_dodge(color_t backdrop, color_t src, int opacity);
color_t rgba_blender_color_burn(color_t backdrop, color_t src, int opacity);
color_t rgba_blender_hard_light(color_t backdrop, color_t src, int opacity);
color_t rgba_blender_soft_light(color_t backdrop, color_t src, int opacity);
color_t rgba_blender_difference(color_t backdrop, color_t src, int opacity);
color_t rgba_blender_exclusion(color_t backdrop, color_t src, int opacity);
color_t rgba_blender_hsl_hue(color_t backdrop, color_t src, int opacity);
color_t rgba_blender_hsl_saturation(color_t backdrop, color_t src, int opacity);
color_t rgba_blender_hsl_color(color_t backdrop, color_t src, int opacity);
color_t rgba_blender_hsl_luminosity(color_t backdrop, color_t src, int opacity);
}
using namespace doc;
static void CustomArguments(benchmark::internal::Benchmark* b) {
b ->Args({ int(rgba(200, 128, 64, 255)), int(rgba(32, 128, 200, 255)), 255 })
->Args({ int(rgba(200, 128, 64, 255)), int(rgba(32, 128, 200, 255)), 128 })
->Args({ int(rgba(200, 128, 64, 255)), int(rgba(32, 128, 200, 255)), 0 })
->Args({ int(rgba(200, 128, 64, 128)), int(rgba(32, 128, 200, 128)), 255 })
->Args({ int(rgba(200, 128, 64, 128)), int(rgba(32, 128, 200, 128)), 128 })
->Args({ int(rgba(200, 128, 64, 128)), int(rgba(32, 128, 200, 128)), 0 })
->Args({ int(rgba(200, 128, 64, 128)), int(rgba(32, 128, 200, 0)), 255 });
}
template<BlendFunc F>
void BM_Rgba(benchmark::State& state) {
color_t a = color_t(state.range(0));
color_t b = color_t(state.range(1));
int opacity = state.range(2);
BlendFunc func = F;
while (state.KeepRunning()) {
color_t c = func(a, b, opacity);
c = func(c, b, opacity);
}
}
BENCHMARK_TEMPLATE(BM_Rgba, rgba_blender_normal)->Apply(CustomArguments);
BENCHMARK_TEMPLATE(BM_Rgba, rgba_blender_multiply)->Apply(CustomArguments);
BENCHMARK_TEMPLATE(BM_Rgba, rgba_blender_screen)->Apply(CustomArguments);
BENCHMARK_TEMPLATE(BM_Rgba, rgba_blender_overlay)->Apply(CustomArguments);
BENCHMARK_TEMPLATE(BM_Rgba, rgba_blender_darken)->Apply(CustomArguments);
BENCHMARK_TEMPLATE(BM_Rgba, rgba_blender_lighten)->Apply(CustomArguments);
BENCHMARK_TEMPLATE(BM_Rgba, rgba_blender_color_dodge)->Apply(CustomArguments);
BENCHMARK_TEMPLATE(BM_Rgba, rgba_blender_color_burn)->Apply(CustomArguments);
BENCHMARK_TEMPLATE(BM_Rgba, rgba_blender_hard_light)->Apply(CustomArguments);
BENCHMARK_TEMPLATE(BM_Rgba, rgba_blender_soft_light)->Apply(CustomArguments);
BENCHMARK_TEMPLATE(BM_Rgba, rgba_blender_difference)->Apply(CustomArguments);
BENCHMARK_TEMPLATE(BM_Rgba, rgba_blender_exclusion)->Apply(CustomArguments);
BENCHMARK_TEMPLATE(BM_Rgba, rgba_blender_hsl_hue)->Apply(CustomArguments);
BENCHMARK_TEMPLATE(BM_Rgba, rgba_blender_hsl_saturation)->Apply(CustomArguments);
BENCHMARK_TEMPLATE(BM_Rgba, rgba_blender_hsl_color)->Apply(CustomArguments);
BENCHMARK_TEMPLATE(BM_Rgba, rgba_blender_hsl_luminosity)->Apply(CustomArguments);
BENCHMARK_MAIN();

View File

@ -119,3 +119,8 @@ set(ENABLE_CNG OFF CACHE BOOL "Enable the use of CNG(Crypto Next Generation)")
add_subdirectory(libarchive)
target_include_directories(archive_static INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/libarchive/libarchive>)
# benchmark
if(ENABLE_BENCHMARKS)
add_subdirectory(benchmark)
endif()

1
third_party/benchmark vendored Submodule

@ -0,0 +1 @@
Subproject commit 710c2b89d8c6e839e51ac148b4e840ce2c009dbb