From da4b6f1527002d5e88b5556fb269e8434fd22598 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 20 May 2022 17:21:04 -0600 Subject: [PATCH] [benchmark-shape] Add variable fonts --- perf/benchmark-shape.cc | 53 +++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/perf/benchmark-shape.cc b/perf/benchmark-shape.cc index 924f4870e..00cf8516d 100644 --- a/perf/benchmark-shape.cc +++ b/perf/benchmark-shape.cc @@ -4,33 +4,52 @@ #include "hb.h" +#define SUBSET_FONT_BASE_PATH "test/subset/data/fonts/" + struct test_input_t { const char *text_path; const char *font_path; + bool is_variable; } tests[] = { {"perf/texts/fa-thelittleprince.txt", - "perf/fonts/Amiri-Regular.ttf"}, + "perf/fonts/Amiri-Regular.ttf", + false}, {"perf/texts/fa-thelittleprince.txt", - "perf/fonts/NotoNastaliqUrdu-Regular.ttf"}, + "perf/fonts/NotoNastaliqUrdu-Regular.ttf", + false}, {"perf/texts/fa-monologue.txt", - "perf/fonts/Amiri-Regular.ttf"}, + "perf/fonts/Amiri-Regular.ttf", + false}, {"perf/texts/fa-monologue.txt", - "perf/fonts/NotoNastaliqUrdu-Regular.ttf"}, + "perf/fonts/NotoNastaliqUrdu-Regular.ttf", + false}, {"perf/texts/en-thelittleprince.txt", - "perf/fonts/Roboto-Regular.ttf"}, + "perf/fonts/Roboto-Regular.ttf", + false}, + + {"perf/texts/en-thelittleprince.txt", + SUBSET_FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", + true}, {"perf/texts/en-words.txt", - "perf/fonts/Roboto-Regular.ttf"}, + "perf/fonts/Roboto-Regular.ttf", + false}, + + {"perf/texts/en-words.txt", + SUBSET_FONT_BASE_PATH "SourceSerifVariable-Roman.ttf", + true}, }; -static void BM_Shape (benchmark::State &state, const test_input_t &input) +static void BM_Shape (benchmark::State &state, + bool is_var, + const test_input_t &input) { hb_font_t *font; { @@ -42,6 +61,12 @@ static void BM_Shape (benchmark::State &state, const test_input_t &input) hb_face_destroy (face); } + if (is_var) + { + hb_variation_t wght = {HB_TAG ('w','g','h','t'), 500}; + hb_font_set_variations (font, &wght, 1); + } + hb_blob_t *text_blob = hb_blob_create_from_file_or_fail (input.text_path); assert (text_blob); unsigned orig_text_length; @@ -76,12 +101,16 @@ int main(int argc, char** argv) { for (auto& test_input : tests) { - char name[1024] = "BM_Shape"; - strcat (name, strrchr (test_input.text_path, '/')); - strcat (name, strrchr (test_input.font_path, '/')); + for (int variable = 0; variable < int (test_input.is_variable) + 1; variable++) + { + char name[1024] = "BM_Shape"; + strcat (name, strrchr (test_input.text_path, '/')); + strcat (name, strrchr (test_input.font_path, '/')); + strcat (name, variable ? "/var" : ""); - benchmark::RegisterBenchmark (name, BM_Shape, test_input) - ->Unit(benchmark::kMillisecond); + benchmark::RegisterBenchmark (name, BM_Shape, variable, test_input) + ->Unit(benchmark::kMillisecond); + } } benchmark::Initialize(&argc, argv);