• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "benchmark/benchmark.h"
2 
3 #include "hb.h"
4 
shape(benchmark::State & state,const char * text_path,hb_direction_t direction,hb_script_t script,const char * font_path)5 static void shape (benchmark::State &state, const char *text_path,
6 		   hb_direction_t direction, hb_script_t script,
7 		   const char *font_path)
8 {
9   hb_font_t *font;
10   {
11     hb_blob_t *blob = hb_blob_create_from_file (font_path);
12     assert (hb_blob_get_length (blob));
13     hb_face_t *face = hb_face_create (blob, 0);
14     hb_blob_destroy (blob);
15     font = hb_font_create (face);
16     hb_face_destroy (face);
17   }
18 
19   hb_blob_t *text_blob = hb_blob_create_from_file (text_path);
20   unsigned text_length;
21   const char *text = hb_blob_get_data (text_blob, &text_length);
22   assert (text_length);
23 
24   hb_buffer_t *buf = hb_buffer_create ();
25   for (auto _ : state)
26   {
27     hb_buffer_add_utf8 (buf, text, text_length, 0, -1);
28     hb_buffer_set_direction (buf, direction);
29     hb_buffer_set_script (buf, script);
30     hb_shape (font, buf, nullptr, 0);
31     hb_buffer_clear_contents (buf);
32   }
33   hb_buffer_destroy (buf);
34 
35   hb_blob_destroy (text_blob);
36   hb_font_destroy (font);
37 }
38 
39 BENCHMARK_CAPTURE (shape, fa-thelittleprince.txt - Amiri,
40 		   "perf/texts/fa-thelittleprince.txt",
41 		   HB_DIRECTION_RTL, HB_SCRIPT_ARABIC,
42 		   "perf/fonts/Amiri-Regular.ttf");
43 BENCHMARK_CAPTURE (shape, fa-thelittleprince.txt - NotoNastaliqUrdu,
44 		   "perf/texts/fa-thelittleprince.txt",
45 		   HB_DIRECTION_RTL, HB_SCRIPT_ARABIC,
46 		   "perf/fonts/NotoNastaliqUrdu-Regular.ttf");
47 
48 BENCHMARK_CAPTURE (shape, fa-monologue.txt - Amiri,
49 		   "perf/texts/fa-monologue.txt",
50 		   HB_DIRECTION_RTL, HB_SCRIPT_ARABIC,
51 		   "perf/fonts/Amiri-Regular.ttf");
52 BENCHMARK_CAPTURE (shape, fa-monologue.txt - NotoNastaliqUrdu,
53 		   "perf/texts/fa-monologue.txt",
54 		   HB_DIRECTION_RTL, HB_SCRIPT_ARABIC,
55 		   "perf/fonts/NotoNastaliqUrdu-Regular.ttf");
56 
57 BENCHMARK_CAPTURE (shape, en-thelittleprince.txt - Roboto,
58 		   "perf/texts/en-thelittleprince.txt",
59 		   HB_DIRECTION_LTR, HB_SCRIPT_LATIN,
60 		   "perf/fonts/Roboto-Regular.ttf");
61 
62 BENCHMARK_CAPTURE (shape, en-words.txt - Roboto,
63 		   "perf/texts/en-words.txt",
64 		   HB_DIRECTION_LTR, HB_SCRIPT_LATIN,
65 		   "perf/fonts/Roboto-Regular.ttf");
66