gauss_blur_gbench.cc (2241B)
1 // Copyright (c) the JPEG XL Project Authors. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 #include <hwy/targets.h> 7 8 #include "benchmark/benchmark.h" 9 #include "lib/jxl/base/status.h" 10 #include "lib/jxl/image_ops.h" 11 #include "tools/gauss_blur.h" 12 13 namespace jxl { 14 namespace { 15 16 void BM_GaussBlur1d(benchmark::State& state) { 17 // Uncomment to disable SIMD and force and scalar implementation 18 // hwy::DisableTargets(~HWY_SCALAR); 19 // Uncomment to run AVX2 20 // hwy::DisableTargets(HWY_AVX3); 21 22 const size_t length = state.range(); 23 const double sigma = 7.0; // (from Butteraugli application) 24 JXL_ASSIGN_OR_DIE(ImageF in, ImageF::Create(length, 1)); 25 const float expected = length; 26 FillImage(expected, &in); 27 28 JXL_ASSIGN_OR_DIE(ImageF temp, ImageF::Create(length, 1)); 29 JXL_ASSIGN_OR_DIE(ImageF out, ImageF::Create(length, 1)); 30 const auto rg = CreateRecursiveGaussian(sigma); 31 for (auto _ : state) { 32 FastGaussian1D(rg, length, in.Row(0), out.Row(0)); 33 // Prevent optimizing out 34 JXL_ASSERT(std::abs(out.ConstRow(0)[length / 2] - expected) / expected < 35 9E-5); 36 } 37 state.SetItemsProcessed(length * state.iterations()); 38 } 39 40 void BM_GaussBlur2d(benchmark::State& state) { 41 // See GaussBlur1d for SIMD changes. 42 43 const size_t xsize = state.range(); 44 const size_t ysize = xsize; 45 const double sigma = 7.0; // (from Butteraugli application) 46 JXL_ASSIGN_OR_DIE(ImageF in, ImageF::Create(xsize, ysize)); 47 const float expected = xsize + ysize; 48 FillImage(expected, &in); 49 50 JXL_ASSIGN_OR_DIE(ImageF temp, ImageF::Create(xsize, ysize)); 51 JXL_ASSIGN_OR_DIE(ImageF out, ImageF::Create(xsize, ysize)); 52 ThreadPool* null_pool = nullptr; 53 const auto rg = CreateRecursiveGaussian(sigma); 54 for (auto _ : state) { 55 FastGaussian(rg, in, null_pool, &temp, &out); 56 // Prevent optimizing out 57 JXL_ASSERT(std::abs(out.ConstRow(ysize / 2)[xsize / 2] - expected) / 58 expected < 59 9E-5); 60 } 61 state.SetItemsProcessed(xsize * ysize * state.iterations()); 62 } 63 64 BENCHMARK(BM_GaussBlur1d)->Range(1 << 8, 1 << 14); 65 BENCHMARK(BM_GaussBlur2d)->Range(1 << 7, 1 << 10); 66 67 } // namespace 68 } // namespace jxl