Hash :
bc5129d7
Author :
Date :
2022-05-04T22:16:03
[perf] use option_t in subset benchmark to select between glyphs and codepoint subset.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
#include "benchmark/benchmark.h"
#include "hb-subset.h"
// TODO(garretrieger): TrueType CJK font.
// TODO(garretrieger): Amiri + Devanagari
enum operation_t
{
subset_codepoints,
subset_glyphs
};
void AddCodepoints(const hb_set_t* codepoints_in_font,
unsigned subset_size,
hb_subset_input_t* input)
{
hb_codepoint_t cp = HB_SET_VALUE_INVALID;
for (unsigned i = 0; i < subset_size; i++) {
// TODO(garretrieger): pick randomly.
if (!hb_set_next (codepoints_in_font, &cp)) return;
hb_set_add (hb_subset_input_unicode_set (input), cp);
}
}
void AddGlyphs(unsigned num_glyphs_in_font,
unsigned subset_size,
hb_subset_input_t* input)
{
for (unsigned i = 0; i < subset_size && i < num_glyphs_in_font; i++) {
// TODO(garretrieger): pick randomly.
hb_set_add (hb_subset_input_glyph_set (input), i);
}
}
/* benchmark for subsetting a font */
static void BM_subset (benchmark::State &state,
operation_t operation,
const char *font_path)
{
unsigned subset_size = state.range(0);
hb_face_t *face;
{
hb_blob_t *blob = hb_blob_create_from_file_or_fail (font_path);
assert (blob);
face = hb_face_create (blob, 0);
hb_blob_destroy (blob);
}
hb_subset_input_t* input = hb_subset_input_create_or_fail ();
assert (input);
{
hb_set_t* all_codepoints = hb_set_create ();
switch (operation) {
case subset_codepoints:
hb_face_collect_unicodes (face, all_codepoints);
AddCodepoints(all_codepoints, subset_size, input);
break;
case subset_glyphs:
unsigned num_glyphs = hb_face_get_glyph_count (face);
AddGlyphs(num_glyphs, subset_size, input);
break;
}
hb_set_destroy (all_codepoints);
}
for (auto _ : state)
{
hb_face_t* subset = hb_subset_or_fail (face, input);
assert (subset);
hb_face_destroy (subset);
}
hb_subset_input_destroy (input);
hb_face_destroy (face);
}
BENCHMARK_CAPTURE (BM_subset, subset_codepoints_roboto,
subset_codepoints,
"perf/fonts/Roboto-Regular.ttf")
->Unit(benchmark::kMillisecond)
->Range(10, 4000);
BENCHMARK_CAPTURE (BM_subset, subset_glyphs_roboto,
subset_glyphs,
"perf/fonts/Roboto-Regular.ttf")
->Unit(benchmark::kMillisecond)
->Range(10, 4000);
BENCHMARK_CAPTURE (BM_subset, subset_codepoints_amiri,
subset_codepoints,
"perf/fonts/Amiri-Regular.ttf")
->Unit(benchmark::kMillisecond)
->Range(10, 4000);
BENCHMARK_CAPTURE (BM_subset, subset_glyphs_amiri,
subset_glyphs,
"perf/fonts/Amiri-Regular.ttf")
->Unit(benchmark::kMillisecond)
->Range(10, 4000);
BENCHMARK_CAPTURE (BM_subset, subset_codepoints_noto_nastaliq_urdu,
subset_codepoints,
"perf/fonts/NotoNastaliqUrdu-Regular.ttf")
->Unit(benchmark::kMillisecond)
->Range(10, 1000);
BENCHMARK_CAPTURE (BM_subset, subset_glyphs_noto_nastaliq_urdu,
subset_glyphs,
"perf/fonts/NotoNastaliqUrdu-Regular.ttf")
->Unit(benchmark::kMillisecond)
->Range(10, 1000);
BENCHMARK_CAPTURE (BM_subset, subset_codepoints_noto_devangari,
subset_codepoints,
"perf/fonts/NotoSansDevanagari-Regular.ttf")
->Unit(benchmark::kMillisecond)
->Range(10, 1000);
BENCHMARK_CAPTURE (BM_subset, subset_glyphs_noto_devangari,
subset_glyphs,
"perf/fonts/NotoSansDevanagari-Regular.ttf")
->Unit(benchmark::kMillisecond)
->Range(10, 1000);
BENCHMARK_CAPTURE (BM_subset, subset_codepoints_mplus1p,
subset_codepoints,
"test/subset/data/fonts/Mplus1p-Regular.ttf")
->Unit(benchmark::kMillisecond)
->Range(10, 10000);
BENCHMARK_CAPTURE (BM_subset, subset_glyphs_mplus1p,
subset_glyphs,
"test/subset/data/fonts/Mplus1p-Regular.ttf")
->Unit(benchmark::kMillisecond)
->Range(10, 10000);
#if 0
BENCHMARK_CAPTURE (BM_subset, subset_codepoints_notocjk,
subset_codepoints,
"perf/fonts/NotoSansCJKsc-VF.ttf")
->Unit(benchmark::kMillisecond)
->Range(10, 100000);
BENCHMARK_CAPTURE (BM_subset, subset_glyphs_notocjk,
subset_glyphs,
"perf/fonts/NotoSansCJKsc-VF.ttf")
->Unit(benchmark::kMillisecond)
->Range(10, 100000);
#endif
BENCHMARK_MAIN();