[instance] add benchmarks for instancing

This commit is contained in:
Qunxin Liu 2022-08-31 12:01:32 -07:00 committed by Behdad Esfahbod
parent 14eb3d37ad
commit 470944901f
3 changed files with 73 additions and 11 deletions

View File

@ -2,30 +2,72 @@
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "hb-subset.h" #include "hb-subset.h"
enum operation_t enum operation_t
{ {
subset_codepoints, subset_codepoints,
subset_glyphs subset_glyphs,
instance,
}; };
struct axis_location_t
{
hb_tag_t axis_tag;
float axis_value;
};
static const axis_location_t
_roboto_flex_instance_opts[] =
{
{HB_TAG ('w', 'g', 'h', 't'), 600.f},
{HB_TAG ('w', 'd', 't', 'h'), 75.f},
{HB_TAG ('o', 'p', 's', 'z'), 90.f},
{HB_TAG ('G', 'R', 'A', 'D'), -100.f},
{HB_TAG ('s', 'l', 'n', 't'), -3.f},
{HB_TAG ('X', 'T', 'R', 'A'), 500.f},
{HB_TAG ('X', 'O', 'P', 'Q'), 150.f},
{HB_TAG ('Y', 'O', 'P', 'Q'), 100.f},
{HB_TAG ('Y', 'T', 'L', 'C'), 480.f},
{HB_TAG ('Y', 'T', 'U', 'C'), 600.f},
{HB_TAG ('Y', 'T', 'A', 'S'), 800.f},
{HB_TAG ('Y', 'T', 'D', 'E'), -50.f},
{HB_TAG ('Y', 'T', 'F', 'I'), 600.f},
};
static const axis_location_t
_mplus_instance_opts[] =
{
{HB_TAG ('w', 'g', 'h', 't'), 800.f},
};
template <typename Type, unsigned int n>
static inline unsigned int ARRAY_LEN (const Type (&)[n]) { return n; }
#define SUBSET_FONT_BASE_PATH "test/subset/data/fonts/" #define SUBSET_FONT_BASE_PATH "test/subset/data/fonts/"
struct test_input_t struct test_input_t
{ {
const char *font_path; const char *font_path;
const unsigned max_subset_size; const unsigned max_subset_size;
const axis_location_t *instance_opts;
const unsigned num_instance_opts;
} tests[] = } tests[] =
{ {
{SUBSET_FONT_BASE_PATH "Roboto-Regular.ttf", 4000}, {SUBSET_FONT_BASE_PATH "Roboto-Regular.ttf", 4000, nullptr, 0},
{SUBSET_FONT_BASE_PATH "Amiri-Regular.ttf", 4000}, {SUBSET_FONT_BASE_PATH "Amiri-Regular.ttf", 4000, nullptr, 0},
{SUBSET_FONT_BASE_PATH "NotoNastaliqUrdu-Regular.ttf", 1000}, {SUBSET_FONT_BASE_PATH "NotoNastaliqUrdu-Regular.ttf", 1000, nullptr, 0},
{SUBSET_FONT_BASE_PATH "NotoSansDevanagari-Regular.ttf", 1000}, {SUBSET_FONT_BASE_PATH "NotoSansDevanagari-Regular.ttf", 1000, nullptr, 0},
{SUBSET_FONT_BASE_PATH "Mplus1p-Regular.ttf", 10000}, {SUBSET_FONT_BASE_PATH "Mplus1p-Regular.ttf", 10000, nullptr, 0},
{SUBSET_FONT_BASE_PATH "SourceHanSans-Regular_subset.otf", 10000}, {SUBSET_FONT_BASE_PATH "SourceHanSans-Regular_subset.otf", 10000, nullptr, 0},
{SUBSET_FONT_BASE_PATH "SourceSansPro-Regular.otf", 2000}, {SUBSET_FONT_BASE_PATH "SourceSansPro-Regular.otf", 2000, nullptr, 0},
{SUBSET_FONT_BASE_PATH "MPLUS1-Variable.ttf", 6000, _mplus_instance_opts, ARRAY_LEN (_mplus_instance_opts)},
{SUBSET_FONT_BASE_PATH "RobotoFlex-Variable.ttf", 900, _roboto_flex_instance_opts, ARRAY_LEN (_roboto_flex_instance_opts)},
#if 0 #if 0
{"perf/fonts/NotoSansCJKsc-VF.ttf", 100000}, {"perf/fonts/NotoSansCJKsc-VF.ttf", 100000},
#endif #endif
@ -58,13 +100,13 @@ void AddGlyphs(unsigned num_glyphs_in_font,
/* benchmark for subsetting a font */ /* benchmark for subsetting a font */
static void BM_subset (benchmark::State &state, static void BM_subset (benchmark::State &state,
operation_t operation, operation_t operation,
const char *font_path) const test_input_t &test_input)
{ {
unsigned subset_size = state.range(0); unsigned subset_size = state.range(0);
hb_face_t *face; hb_face_t *face;
{ {
hb_blob_t *blob = hb_blob_create_from_file_or_fail (font_path); hb_blob_t *blob = hb_blob_create_from_file_or_fail (test_input.font_path);
assert (blob); assert (blob);
face = hb_face_create (blob, 0); face = hb_face_create (blob, 0);
hb_blob_destroy (blob); hb_blob_destroy (blob);
@ -90,6 +132,20 @@ static void BM_subset (benchmark::State &state,
AddGlyphs(num_glyphs, subset_size, input); AddGlyphs(num_glyphs, subset_size, input);
} }
break; break;
case instance:
{
hb_set_t* all_codepoints = hb_set_create ();
hb_face_collect_unicodes (face, all_codepoints);
AddCodepoints(all_codepoints, subset_size, input);
hb_set_destroy (all_codepoints);
for (unsigned i = 0; i < test_input.num_instance_opts; i++)
hb_subset_input_pin_axis_location (input, face,
test_input.instance_opts[i].axis_tag,
test_input.instance_opts[i].axis_value);
}
break;
} }
for (auto _ : state) for (auto _ : state)
@ -108,11 +164,14 @@ static void test_subset (operation_t op,
benchmark::TimeUnit time_unit, benchmark::TimeUnit time_unit,
const test_input_t &test_input) const test_input_t &test_input)
{ {
if (op == instance && test_input.instance_opts == nullptr)
return;
char name[1024] = "BM_subset/"; char name[1024] = "BM_subset/";
strcat (name, op_name); strcat (name, op_name);
strcat (name, strrchr (test_input.font_path, '/')); strcat (name, strrchr (test_input.font_path, '/'));
benchmark::RegisterBenchmark (name, BM_subset, op, test_input.font_path) benchmark::RegisterBenchmark (name, BM_subset, op, test_input)
->Range(10, test_input.max_subset_size) ->Range(10, test_input.max_subset_size)
->Unit(time_unit); ->Unit(time_unit);
} }
@ -133,6 +192,9 @@ int main(int argc, char** argv)
TEST_OPERATION (subset_glyphs, benchmark::kMillisecond); TEST_OPERATION (subset_glyphs, benchmark::kMillisecond);
TEST_OPERATION (subset_codepoints, benchmark::kMillisecond); TEST_OPERATION (subset_codepoints, benchmark::kMillisecond);
#ifdef HB_EXPERIMENTAL_API
TEST_OPERATION (instance, benchmark::kMillisecond);
#endif
#undef TEST_OPERATION #undef TEST_OPERATION

Binary file not shown.

Binary file not shown.