[perf] Make subset benchmark data driven.

This commit is contained in:
Garret Rieger 2022-05-10 19:40:37 +00:00 committed by Behdad Esfahbod
parent 0a42410dc8
commit 52d59bf150
2 changed files with 52 additions and 101 deletions

View File

@ -1,9 +1,8 @@
#include "benchmark/benchmark.h" #include "benchmark/benchmark.h"
#include <cstring>
#include "hb-subset.h" #include "hb-subset.h"
// TODO(garretrieger): TrueType CJK font.
// TODO(garretrieger): Amiri + Devanagari
enum operation_t enum operation_t
{ {
@ -11,6 +10,26 @@ enum operation_t
subset_glyphs subset_glyphs
}; };
#define SUBSET_FONT_BASE_PATH "test/subset/data/fonts/"
struct test_input_t
{
const char *font_path;
const unsigned max_subset_size;
} tests[] =
{
{SUBSET_FONT_BASE_PATH "Roboto-Regular.ttf", 4000},
{SUBSET_FONT_BASE_PATH "Amiri-Regular.ttf", 4000},
{SUBSET_FONT_BASE_PATH "NotoNastaliqUrdu-Regular.ttf", 1000},
{SUBSET_FONT_BASE_PATH "NotoSansDevanagari-Regular.ttf", 1000},
{SUBSET_FONT_BASE_PATH "Mplus1p-Regular.ttf", 10000},
{SUBSET_FONT_BASE_PATH "SourceHanSans-Regular_subset.otf", 10000},
{SUBSET_FONT_BASE_PATH "SourceSansPro-Regular.otf", 2000},
#if 0
{"perf/fonts/NotoSansCJKsc-VF.ttf", 100000},
#endif
};
void AddCodepoints(const hb_set_t* codepoints_in_font, void AddCodepoints(const hb_set_t* codepoints_in_font,
unsigned subset_size, unsigned subset_size,
hb_subset_input_t* input) hb_subset_input_t* input)
@ -77,108 +96,40 @@ static void BM_subset (benchmark::State &state,
hb_face_destroy (face); hb_face_destroy (face);
} }
BENCHMARK_CAPTURE (BM_subset, subset_codepoints_roboto, static void test_subset (operation_t op,
subset_codepoints, const char *op_name,
"perf/fonts/Roboto-Regular.ttf") benchmark::TimeUnit time_unit,
->Unit(benchmark::kMillisecond) const test_input_t &test_input)
->Range(10, 4000); {
char name[1024] = "BM_subset/";
strcat (name, op_name);
strcat (name, strrchr (test_input.font_path, '/'));
BENCHMARK_CAPTURE (BM_subset, subset_glyphs_roboto, benchmark::RegisterBenchmark (name, BM_subset, op, test_input.font_path)
subset_glyphs, ->Range(10, test_input.max_subset_size)
"perf/fonts/Roboto-Regular.ttf") ->Unit(time_unit);
->Unit(benchmark::kMillisecond) }
->Range(10, 4000);
BENCHMARK_CAPTURE (BM_subset, subset_codepoints_amiri, static void test_operation (operation_t op,
subset_codepoints, const char *op_name,
"perf/fonts/Amiri-Regular.ttf") benchmark::TimeUnit time_unit)
->Unit(benchmark::kMillisecond) {
->Range(10, 4000); for (auto& test_input : tests)
{
test_subset (op, op_name, time_unit, test_input);
}
}
BENCHMARK_CAPTURE (BM_subset, subset_glyphs_amiri, int main(int argc, char** argv)
subset_glyphs, {
"perf/fonts/Amiri-Regular.ttf") #define TEST_OPERATION(op, time_unit) test_operation (op, #op, time_unit)
->Unit(benchmark::kMillisecond)
->Range(10, 4000);
BENCHMARK_CAPTURE (BM_subset, subset_codepoints_noto_nastaliq_urdu, TEST_OPERATION (subset_glyphs, benchmark::kMillisecond);
subset_codepoints, TEST_OPERATION (subset_codepoints, benchmark::kMillisecond);
"perf/fonts/NotoNastaliqUrdu-Regular.ttf")
->Unit(benchmark::kMillisecond)
->Range(10, 1000);
BENCHMARK_CAPTURE (BM_subset, subset_glyphs_noto_nastaliq_urdu, #undef TEST_OPERATION
subset_glyphs,
"perf/fonts/NotoNastaliqUrdu-Regular.ttf")
->Unit(benchmark::kMillisecond)
->Range(10, 1000);
BENCHMARK_CAPTURE (BM_subset, subset_codepoints_noto_devangari, benchmark::Initialize(&argc, argv);
subset_codepoints, benchmark::RunSpecifiedBenchmarks();
"perf/fonts/NotoSansDevanagari-Regular.ttf") benchmark::Shutdown();
->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);
BENCHMARK_CAPTURE (BM_subset, subset_codepoints_sourcehansans,
subset_codepoints,
"test/subset/data/fonts/SourceHanSans-Regular_subset.otf")
->Unit(benchmark::kMillisecond)
->Range(10, 10000);
BENCHMARK_CAPTURE (BM_subset, subset_glyphs_sourcehansans,
subset_glyphs,
"test/subset/data/fonts/SourceHanSans-Regular_subset.otf")
->Unit(benchmark::kMillisecond)
->Range(10, 10000);
BENCHMARK_CAPTURE (BM_subset, subset_codepoints_sourcesanspro,
subset_codepoints,
"test/subset/data/fonts/SourceSansPro-Regular.otf")
->Unit(benchmark::kMillisecond)
->Range(10, 2048);
BENCHMARK_CAPTURE (BM_subset, subset_glyphs_sourcesanspro,
subset_glyphs,
"test/subset/data/fonts/SourceSansPro-Regular.otf")
->Unit(benchmark::kMillisecond)
->Range(10, 2048);
#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();