diff --git a/Makefile.am b/Makefile.am index 68131937d..e832da0c5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -164,6 +164,7 @@ noinst_PROGRAMS = clientnb \ connect \ lokitclient \ coolmap \ + coolbench \ coolsocketdump if ENABLE_LIBFUZZER @@ -270,6 +271,14 @@ coolmount_SOURCES = tools/mount.cpp coolmap_SOURCES = tools/map.cpp +coolbench_SOURCES = tools/Benchmark.cpp \ + common/DummyTraceEventEmitter.cpp \ + common/Log.cpp \ + common/StringVector.cpp \ + common/Util.cpp \ + common/Simd.cpp +coolbench_LDADD = libsimd.a + coolconvert_SOURCES = tools/Tool.cpp coolstress_CPPFLAGS = -DTDOC=\"$(abs_top_srcdir)/test/data\" ${include_paths} diff --git a/tools/Benchmark.cpp b/tools/Benchmark.cpp new file mode 100644 index 000000000..20760062d --- /dev/null +++ b/tools/Benchmark.cpp @@ -0,0 +1,84 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * Copyright the Collabora Online contributors. + * + * SPDX-License-Identifier: MPL-2.0 + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +/* + * Benchmark various bits of cool code. + */ + +#include "config.h" + +#include + +#include +#include + +typedef std::vector Pixmap; + +std::vector pixmaps; + +class DeltaTests { +public: + static void rleBitmap(Pixmap &pix) + { + TileLocation loc = { 0, 0, 0, 0, 0 }; + DeltaGenerator::DeltaData rleData( + 1 /*wid*/, reinterpret_cast(pix.data()), + 0, 0, 256, 256, loc, 256, 256); + } + + static void timeRLE(const char *description) + { + std::cout << "Benchmark " << description << "\n"; + + int deltas = 0; + const auto start = std::chrono::steady_clock::now(); + + // check we have enough work: + int maxIters = (50000 + pixmaps.size() - 1) / pixmaps.size(); + for (int it = 0; it < maxIters; ++it) + { +// std::cerr << "iter " << it << "\n"; + for (Pixmap &pix : pixmaps) + { + deltas++; + rleBitmap(pix); + } + } + + const auto end = std::chrono::steady_clock::now(); + + std::cout << "took: " << + std::chrono::duration_cast(end - start).count() << "ms - "; + + std::cout << "time/rle: " << + (1.0*std::chrono::duration_cast(end - start).count())/deltas << "us\n"; + } +}; + +int main (int argc, char **argv) +{ + for (int i = 1; i < argc; i++) + { + uint32_t height, width, rowBytes; + Pixmap img = Png::loadPng(argv[i], height, width, rowBytes); +// std::cout << "Loaded: " << argv[i] << " " << width << "x" << height << "\n"; + pixmaps.push_back(img); + } + + DeltaTests::timeRLE("CPU"); + + simd::init(); + + DeltaTests::timeRLE("SIMD"); + + return 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */