From c224178a0995a149ec73758c821e4fe26dbf8819 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 13 Oct 2024 20:21:35 -0600 Subject: [PATCH] [perf] Add hb-benchmark.hh --- perf/benchmark-font.cc | 30 ++++---------------- perf/benchmark-map.cc | 9 +----- perf/benchmark-ot.cc | 7 +---- perf/benchmark-set.cc | 9 +----- perf/benchmark-shape.cc | 21 ++------------ perf/benchmark-subset.cc | 17 ++--------- perf/hb-benchmark.hh | 61 ++++++++++++++++++++++++++++++++++++++++ perf/meson.build | 8 +++--- 8 files changed, 79 insertions(+), 83 deletions(-) create mode 100644 perf/hb-benchmark.hh diff --git a/perf/benchmark-font.cc b/perf/benchmark-font.cc index dd2da0446..5fb7bd2bb 100644 --- a/perf/benchmark-font.cc +++ b/perf/benchmark-font.cc @@ -1,20 +1,4 @@ -#include "benchmark/benchmark.h" -#include -#include - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "hb.h" -#include "hb-ot.h" -#ifdef HAVE_FREETYPE -#include "hb-ft.h" -#endif -#ifdef HAVE_CORETEXT -#include "hb-coretext.h" -#endif - +#include "hb-benchmark.hh" #define SUBSET_FONT_BASE_PATH "test/subset/data/fonts/" @@ -103,10 +87,8 @@ static void BM_Font (benchmark::State &state, hb_font_t *font; unsigned num_glyphs; { - hb_blob_t *blob = hb_blob_create_from_file_or_fail (test_input.font_path); - assert (blob); - hb_face_t *face = hb_face_create (blob, 0); - hb_blob_destroy (blob); + hb_face_t *face = hb_benchmark_face_create_from_file_or_fail (test_input.font_path, 0); + assert (face); num_glyphs = hb_face_get_glyph_count (face); font = hb_font_create (face); hb_face_destroy (face); @@ -217,10 +199,8 @@ static void BM_Font (benchmark::State &state, { for (auto _ : state) { - hb_blob_t *blob = hb_blob_create_from_file_or_fail (test_input.font_path); - assert (blob); - hb_face_t *face = hb_face_create (blob, 0); - hb_blob_destroy (blob); + hb_face_t *face = hb_benchmark_face_create_from_file_or_fail (test_input.font_path, 0); + assert (face); hb_font_t *font = hb_font_create (face); hb_face_destroy (face); diff --git a/perf/benchmark-map.cc b/perf/benchmark-map.cc index b2f6daeb9..fbdf17c9a 100644 --- a/perf/benchmark-map.cc +++ b/perf/benchmark-map.cc @@ -1,11 +1,4 @@ -/* - * Benchmarks for hb_map_t operations. - */ -#include "benchmark/benchmark.h" - -#include -#include -#include "hb.h" +#include "hb-benchmark.hh" void RandomMap(unsigned size, hb_map_t* out, hb_set_t* key_sample) { hb_map_clear(out); diff --git a/perf/benchmark-ot.cc b/perf/benchmark-ot.cc index c79c384a0..812c0da4b 100644 --- a/perf/benchmark-ot.cc +++ b/perf/benchmark-ot.cc @@ -1,9 +1,4 @@ -/* - * Benchmarks for hb_set_t operations. - */ -#include "benchmark/benchmark.h" - -#include "hb-ot.h" +#include "hb-benchmark.hh" static void BM_hb_ot_tags_from_script_and_language (benchmark::State& state, hb_script_t script, diff --git a/perf/benchmark-set.cc b/perf/benchmark-set.cc index c170acfc0..098082186 100644 --- a/perf/benchmark-set.cc +++ b/perf/benchmark-set.cc @@ -1,11 +1,4 @@ -/* - * Benchmarks for hb_set_t operations. - */ -#include "benchmark/benchmark.h" - -#include -#include -#include "hb.h" +#include "hb-benchmark.hh" void RandomSet(unsigned size, unsigned max_value, hb_set_t* out) { hb_set_clear(out); diff --git a/perf/benchmark-shape.cc b/perf/benchmark-shape.cc index f44b3e58f..490eda2b9 100644 --- a/perf/benchmark-shape.cc +++ b/perf/benchmark-shape.cc @@ -1,17 +1,4 @@ -#include "benchmark/benchmark.h" -#include - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include "hb.h" -#include "hb-ot.h" -#ifdef HAVE_FREETYPE -#include "hb-ft.h" -#endif +#include "hb-benchmark.hh" #define SUBSET_FONT_BASE_PATH "test/subset/data/fonts/" @@ -64,10 +51,8 @@ static void BM_Shape (benchmark::State &state, { hb_font_t *font; { - hb_blob_t *blob = hb_blob_create_from_file_or_fail (input.font_path); - assert (blob); - hb_face_t *face = hb_face_create (blob, 0); - hb_blob_destroy (blob); + hb_face_t *face = hb_benchmark_face_create_from_file_or_fail (input.font_path, 0); + assert (face); font = hb_font_create (face); hb_face_destroy (face); } diff --git a/perf/benchmark-subset.cc b/perf/benchmark-subset.cc index 13e282dc3..30a60b0d6 100644 --- a/perf/benchmark-subset.cc +++ b/perf/benchmark-subset.cc @@ -1,13 +1,4 @@ -#include "benchmark/benchmark.h" -#include -#include - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "hb-subset.h" - +#include "hb-benchmark.hh" enum operation_t { @@ -148,10 +139,8 @@ static void BM_subset (benchmark::State &state, if (!cached_font_path || strcmp (cached_font_path, test_input.font_path)) { - hb_blob_t *blob = hb_blob_create_from_file_or_fail (test_input.font_path); - assert (blob); - face = hb_face_create (blob, 0); - hb_blob_destroy (blob); + hb_face_t *face = hb_benchmark_face_create_from_file_or_fail (test_input.font_path, 0); + assert (face); face = preprocess_face (face); diff --git a/perf/hb-benchmark.hh b/perf/hb-benchmark.hh new file mode 100644 index 000000000..5c9cfef04 --- /dev/null +++ b/perf/hb-benchmark.hh @@ -0,0 +1,61 @@ +/* + * Copyright © 2024 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Author(s): Behdad Esfahbod + */ + +#ifndef HB_BENCHMARK_HH +#define HB_BENCHMARK_HH + +#include + +#include +#include + +#include +#ifdef HAVE_FREETYPE +#include +#endif +#ifdef HAVE_CORETEXT +#include +#endif + +#include + +#include +#include +#include + + +HB_BEGIN_DECLS + +static inline hb_face_t * +hb_benchmark_face_create_from_file_or_fail (const char *font_path, + unsigned face_index) +{ + return hb_face_create_from_file_or_fail (font_path, face_index); +} + +HB_END_DECLS + +#endif /* HB_BENCHMARK_HH */ diff --git a/perf/meson.build b/perf/meson.build index ae122f439..1465806d5 100644 --- a/perf/meson.build +++ b/perf/meson.build @@ -13,7 +13,7 @@ benchmark('benchmark-font', executable('benchmark-font', 'benchmark-font.cc', benchmark('benchmark-map', executable('benchmark-map', 'benchmark-map.cc', dependencies: [ - google_benchmark_dep, + google_benchmark_dep, freetype_dep, ], cpp_args: [], include_directories: [incconfig, incsrc], @@ -23,7 +23,7 @@ benchmark('benchmark-map', executable('benchmark-map', 'benchmark-map.cc', benchmark('benchmark-ot', executable('benchmark-ot', 'benchmark-ot.cc', dependencies: [ - google_benchmark_dep, + google_benchmark_dep, freetype_dep, ], cpp_args: [], include_directories: [incconfig, incsrc], @@ -33,7 +33,7 @@ benchmark('benchmark-ot', executable('benchmark-ot', 'benchmark-ot.cc', benchmark('benchmark-set', executable('benchmark-set', 'benchmark-set.cc', dependencies: [ - google_benchmark_dep, + google_benchmark_dep, freetype_dep, ], cpp_args: [], include_directories: [incconfig, incsrc], @@ -53,7 +53,7 @@ benchmark('benchmark-shape', executable('benchmark-shape', 'benchmark-shape.cc', benchmark('benchmark-subset', executable('benchmark-subset', 'benchmark-subset.cc', dependencies: [ - google_benchmark_dep, + google_benchmark_dep, freetype_dep, ], cpp_args: [], include_directories: [incconfig, incsrc],