From: Carl Hetherington Date: Wed, 28 Oct 2020 15:25:32 +0000 (+0100) Subject: Add a simple benchmark for scaling images. X-Git-Url: https://main.carlh.net/gitweb/?a=commitdiff_plain;ds=sidebyside;h=b02d241e59daae86bf41a5598c3c77e9ccc0f67a;p=dcpomatic.git Add a simple benchmark for scaling images. --- diff --git a/benchmark/scaling.cc b/benchmark/scaling.cc new file mode 100644 index 000000000..93ab7869b --- /dev/null +++ b/benchmark/scaling.cc @@ -0,0 +1,82 @@ +/* + Copyright (C) 2020 Carl Hetherington + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see . + +*/ + + +#include "lib/compose.hpp" +#include "lib/image.h" +#include "lib/timer.h" + + +using boost::shared_ptr; + + +#define ITERATIONS 500 + + +static +shared_ptr +dummy_image(dcp::Size size) +{ + shared_ptr image(new Image(AV_PIX_FMT_RGB24, size, true)); + int v = 0; + for (int y = 0; y < size.height; ++y) { + for (int c = 0; c < image->planes(); ++c) { + uint8_t* p = image->data()[c] + y * image->stride()[c]; + int const line_size = image->line_size()[c]; + for (int x = 0; x < line_size; ++x) { + *p++ = v++ % 256; + } + } + } + + return image; +} + + +static +void +test (dcp::Size from, dcp::Size to, bool fast) +{ + shared_ptr image = dummy_image(from); + PeriodTimer pt (String::compose("%1:%2 -> %3:%4 %5", from.width, from.height, to.width, to.height, fast ? "fast" : "slow")); + for (int i = 0; i < ITERATIONS; ++i) { + image->scale (to, dcp::YUV_TO_RGB_REC709, AV_PIX_FMT_RGB48, true, fast); + } +} + + +int +main () +{ + test (dcp::Size(1998, 1080), dcp::Size(1998, 1080), true); + test (dcp::Size(1998, 1080), dcp::Size(1998, 1080), false); + + test (dcp::Size(1998, 1080), dcp::Size(2006, 1088), true); + test (dcp::Size(1998, 1080), dcp::Size(2006, 1088), false); + + test (dcp::Size(996, 540), dcp::Size(1998, 1080), true); + test (dcp::Size(996, 540), dcp::Size(1998, 1080), false); + + test (dcp::Size(498, 270), dcp::Size(1998, 1080), true); + test (dcp::Size(498, 270), dcp::Size(1998, 1080), false); + + return 0; +} + diff --git a/benchmark/wscript b/benchmark/wscript new file mode 100644 index 000000000..4ca3dff2d --- /dev/null +++ b/benchmark/wscript @@ -0,0 +1,27 @@ +# +# Copyright (C) 2020 Carl Hetherington +# +# This file is part of DCP-o-matic. +# +# DCP-o-matic is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# DCP-o-matic is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with DCP-o-matic. If not, see . +# + +def build(bld): + for p in ['scaling']: + obj = bld(features='cxx cxxprogram') + obj.name = p + obj.uselib = "DCP" + obj.use = 'libdcpomatic2' + obj.source = p + ".cc" + obj.target = p diff --git a/run/benchmark b/run/benchmark new file mode 100755 index 000000000..1106e183e --- /dev/null +++ b/run/benchmark @@ -0,0 +1,31 @@ +#!/bin/bash +# +# run/benchmark + +executable=build/benchmark/$1 + +if [ "$1" == "--debug" ]; then + shift; + gdb --args $executable --catch_system_errors=no --log_level=test_suite +elif [ "$1" == "--backtrace" ]; then + shift; + gdb -batch -ex "run" -ex "thread apply all bt" -return-child-result --args $executable --catch_system_errors=yes +elif [ "$1" == "--valgrind" ]; then + shift; + valgrind --tool="memcheck" --suppressions=suppressions $executable +elif [ "$1" == "--callgrind" ]; then + shift; + valgrind --tool="callgrind" $executable +elif [ "$1" == "--quiet" ]; then + shift; + $executable --catch_system_errors=no +elif [ "$1" == "--drd" ]; then + shift; + valgrind --tool="drd" $executable +elif [ "$1" == "--helgrind" ]; then + shift; + valgrind --tool="helgrind" $executable +else + ulimit -c unlimited + $executable --catch_system_errors=no --log_level=test_suite +fi diff --git a/wscript b/wscript index 00665bbac..16a778034 100644 --- a/wscript +++ b/wscript @@ -631,6 +631,7 @@ def build(bld): bld.recurse('src') bld.recurse('graphics') + bld.recurse('benchmark') if not bld.env.DISABLE_TESTS: bld.recurse('test')