| 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 |
#include <stdlib.h> |
| 35 |
#include <stdio.h> |
| 36 |
|
| 37 |
#include <glib.h> |
| 38 |
|
| 39 |
#include <groonga.h> |
| 40 |
|
| 41 |
#include "lib/benchmark.h" |
| 42 |
|
| 43 |
#include "../lib/nfkc50.c" |
| 44 |
|
| 45 |
#define MAX_UNICODE 0x110000 |
| 46 |
#define BUFFER_SIZE 0x100 |
| 47 |
|
| 48 |
static inline int |
| 49 |
ucs2utf8(unsigned int i, unsigned char *buf) |
| 50 |
{ |
| 51 |
unsigned char *p = buf; |
| 52 |
if (i < 0x80) { |
| 53 |
*p++ = i; |
| 54 |
} else { |
| 55 |
if (i < 0x800) { |
| 56 |
*p++ = (i >> 6) | 0xc0; |
| 57 |
} else { |
| 58 |
if (i < 0x00010000) { |
| 59 |
*p++ = (i >> 12) | 0xe0; |
| 60 |
} else { |
| 61 |
if (i < 0x00200000) { |
| 62 |
*p++ = (i >> 18) | 0xf0; |
| 63 |
} else { |
| 64 |
if (i < 0x04000000) { |
| 65 |
*p++ = (i >> 24) | 0xf8; |
| 66 |
} else if (i < 0x80000000) { |
| 67 |
*p++ = (i >> 30) | 0xfc; |
| 68 |
*p++ = ((i >> 24) & 0x3f) | 0x80; |
| 69 |
} |
| 70 |
*p++ = ((i >> 18) & 0x3f) | 0x80; |
| 71 |
} |
| 72 |
*p++ = ((i >> 12) & 0x3f) | 0x80; |
| 73 |
} |
| 74 |
*p++ = ((i >> 6) & 0x3f) | 0x80; |
| 75 |
} |
| 76 |
*p++ = (0x3f & i) | 0x80; |
| 77 |
} |
| 78 |
*p = '\0'; |
| 79 |
return (p - buf); |
| 80 |
} |
| 81 |
|
| 82 |
static void |
| 83 |
bench_char_type(gpointer user_data) |
| 84 |
{ |
| 85 |
uint64_t code_point; |
| 86 |
char utf8[7]; |
| 87 |
|
| 88 |
for (code_point = 1; code_point < MAX_UNICODE; code_point++) { |
| 89 |
ucs2utf8(code_point, (unsigned char *)utf8); |
| 90 |
grn_nfkc50_char_type(utf8); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
static void |
| 95 |
bench_decompose(gpointer user_data) |
| 96 |
{ |
| 97 |
uint64_t code_point; |
| 98 |
char utf8[7]; |
| 99 |
|
| 100 |
for (code_point = 1; code_point < MAX_UNICODE; code_point++) { |
| 101 |
ucs2utf8(code_point, (unsigned char *)utf8); |
| 102 |
grn_nfkc50_decompose(utf8); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
static void |
| 107 |
bench_compose_no_change(gpointer user_data) |
| 108 |
{ |
| 109 |
uint64_t prefix_code_point; |
| 110 |
uint64_t suffix_code_point = 0x61; |
| 111 |
char prefix_utf8[7]; |
| 112 |
char suffix_utf8[7]; |
| 113 |
|
| 114 |
ucs2utf8(suffix_code_point, (unsigned char *)suffix_utf8); |
| 115 |
for (prefix_code_point = 1; |
| 116 |
prefix_code_point < MAX_UNICODE; |
| 117 |
prefix_code_point++) { |
| 118 |
ucs2utf8(prefix_code_point, (unsigned char *)prefix_utf8); |
| 119 |
grn_nfkc50_compose(prefix_utf8, suffix_utf8); |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
static void |
| 124 |
bench_compose_change(gpointer user_data) |
| 125 |
{ |
| 126 |
uint64_t prefix_code_point; |
| 127 |
uint64_t suffix_code_point = 0x11ba; |
| 128 |
char prefix_utf8[7]; |
| 129 |
char suffix_utf8[7]; |
| 130 |
|
| 131 |
ucs2utf8(suffix_code_point, (unsigned char *)suffix_utf8); |
| 132 |
for (prefix_code_point = 1; |
| 133 |
prefix_code_point < MAX_UNICODE; |
| 134 |
prefix_code_point++) { |
| 135 |
ucs2utf8(prefix_code_point, (unsigned char *)prefix_utf8); |
| 136 |
grn_nfkc50_compose(prefix_utf8, suffix_utf8); |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
int |
| 233 |
main(int argc, gchar **argv) |
| 234 |
{ |
| 235 |
grn_rc rc; |
| 236 |
BenchReporter *reporter; |
| 237 |
gint n = 10; |
| 238 |
|
| 239 |
rc = grn_init(); |
| 240 |
if (rc != GRN_SUCCESS) { |
| 241 |
g_print("failed to initialize Groonga: <%d>: %s\n", |
| 242 |
rc, grn_get_global_error_message()); |
| 243 |
return EXIT_FAILURE; |
| 244 |
} |
| 245 |
bench_init(&argc, &argv); |
| 246 |
|
| 247 |
reporter = bench_reporter_new(); |
| 248 |
|
| 249 |
if (g_getenv("N")) { |
| 250 |
n = atoi(g_getenv("N")); |
| 251 |
} |
| 252 |
|
| 253 |
#define REGISTER(label, bench_function) \ |
| 254 |
bench_reporter_register(reporter, label, n, \ |
| 255 |
NULL, \ |
| 256 |
bench_function, \ |
| 257 |
NULL, \ |
| 258 |
NULL) |
| 259 |
REGISTER("char_type ", bench_char_type); |
| 260 |
REGISTER("decompose ", bench_decompose); |
| 261 |
REGISTER("compose - no change", bench_compose_no_change); |
| 262 |
REGISTER("compose - change", bench_compose_change); |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
#undef REGISTER |
| 270 |
|
| 271 |
bench_reporter_run(reporter); |
| 272 |
g_object_unref(reporter); |
| 273 |
|
| 274 |
return EXIT_SUCCESS; |
| 275 |
} |