| 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 |
#include <string.h> |
| 51 |
#include <stdlib.h> |
| 52 |
|
| 53 |
#include <grn_db.h> |
| 54 |
#include <groonga.h> |
| 55 |
|
| 56 |
#include "lib/benchmark.h" |
| 57 |
|
| 58 |
#define GET(context, name) (grn_ctx_get(context, name, strlen(name))) |
| 59 |
|
| 60 |
grn_obj *grn_expr_get_value(grn_ctx *ctx, grn_obj *expr, int offset); |
| 61 |
|
| 62 |
typedef struct _BenchmarkData |
| 63 |
{ |
| 64 |
gchar *base_dir; |
| 65 |
gboolean report_result; |
| 66 |
|
| 67 |
grn_ctx *context; |
| 68 |
grn_obj *database; |
| 69 |
grn_obj *geo_distance_proc; |
| 70 |
grn_obj *expression; |
| 71 |
grn_obj *start_point; |
| 72 |
grn_obj *end_point; |
| 73 |
} BenchmarkData; |
| 74 |
|
| 75 |
static void |
| 76 |
bench_geo_distance(gpointer user_data) |
| 77 |
{ |
| 78 |
BenchmarkData *data = user_data; |
| 79 |
|
| 80 |
grn_proc_call(data->context, data->geo_distance_proc, |
| 81 |
2, data->expression); |
| 82 |
} |
| 83 |
|
| 84 |
static void |
| 85 |
bench_setup_common(gpointer user_data) |
| 86 |
{ |
| 87 |
BenchmarkData *data = user_data; |
| 88 |
|
| 89 |
grn_ctx_init(data->context, GRN_CTX_USE_QL); |
| 90 |
data->database = grn_db_create(data->context, NULL, NULL); |
| 91 |
data->expression = grn_expr_create(data->context, NULL, 0); |
| 92 |
} |
| 93 |
|
| 94 |
static void |
| 95 |
bench_setup_points(gpointer user_data, |
| 96 |
const gchar *start_point_string, |
| 97 |
const gchar *end_point_string, |
| 98 |
grn_builtin_type wgs84_or_tgs) |
| 99 |
{ |
| 100 |
BenchmarkData *data = user_data; |
| 101 |
grn_obj start_point_text, end_point_text; |
| 102 |
|
| 103 |
GRN_TEXT_INIT(&start_point_text, 0); |
| 104 |
GRN_TEXT_INIT(&end_point_text, 0); |
| 105 |
GRN_TEXT_SETS(data->context, &start_point_text, start_point_string); |
| 106 |
GRN_TEXT_SETS(data->context, &end_point_text, end_point_string); |
| 107 |
|
| 108 |
data->start_point = grn_obj_open(data->context, GRN_BULK, 0, wgs84_or_tgs); |
| 109 |
data->end_point = grn_obj_open(data->context, GRN_BULK, 0, wgs84_or_tgs); |
| 110 |
grn_obj_cast(data->context, &start_point_text, data->start_point, false); |
| 111 |
grn_obj_cast(data->context, &end_point_text, data->end_point, false); |
| 112 |
grn_ctx_push(data->context, data->start_point); |
| 113 |
grn_ctx_push(data->context, data->end_point); |
| 114 |
|
| 115 |
grn_obj_unlink(data->context, &start_point_text); |
| 116 |
grn_obj_unlink(data->context, &end_point_text); |
| 117 |
} |
| 118 |
|
| 119 |
static void |
| 120 |
bench_setup_wgs84(gpointer user_data) |
| 121 |
{ |
| 122 |
bench_setup_common(user_data); |
| 123 |
bench_setup_points(user_data, |
| 124 |
"127980000x502560000", |
| 125 |
"128880000x503640000", |
| 126 |
GRN_DB_WGS84_GEO_POINT); |
| 127 |
} |
| 128 |
|
| 129 |
static void |
| 130 |
bench_setup_tgs(gpointer user_data) |
| 131 |
{ |
| 132 |
bench_setup_common(user_data); |
| 133 |
bench_setup_points(user_data, |
| 134 |
"127980000x502560000", |
| 135 |
"128880000x503640000", |
| 136 |
GRN_DB_TOKYO_GEO_POINT); |
| 137 |
} |
| 138 |
|
| 139 |
static void |
| 140 |
bench_setup_rectangular_wgs84(gpointer user_data) |
| 141 |
{ |
| 142 |
BenchmarkData *data = user_data; |
| 143 |
|
| 144 |
bench_setup_wgs84(user_data); |
| 145 |
data->geo_distance_proc = GET(data->context, "geo_distance"); |
| 146 |
} |
| 147 |
|
| 148 |
static void |
| 149 |
bench_setup_rectangular_tgs(gpointer user_data) |
| 150 |
{ |
| 151 |
BenchmarkData *data = user_data; |
| 152 |
|
| 153 |
bench_setup_tgs(user_data); |
| 154 |
data->geo_distance_proc = GET(data->context, "geo_distance"); |
| 155 |
} |
| 156 |
|
| 157 |
static void |
| 158 |
bench_setup_rectangular_wgs84_1st_to_2nd_quadrant_short(gpointer user_data) |
| 159 |
{ |
| 160 |
BenchmarkData *data = user_data; |
| 161 |
|
| 162 |
bench_setup_common(user_data); |
| 163 |
bench_setup_points(user_data, |
| 164 |
"128452975x503157902", |
| 165 |
"139380000x-31920000", |
| 166 |
GRN_DB_WGS84_GEO_POINT); |
| 167 |
data->geo_distance_proc = GET(data->context, "geo_distance"); |
| 168 |
} |
| 169 |
|
| 170 |
static void |
| 171 |
bench_setup_rectangular_wgs84_2nd_to_1st_quadrant_short(gpointer user_data) |
| 172 |
{ |
| 173 |
BenchmarkData *data = user_data; |
| 174 |
|
| 175 |
bench_setup_common(user_data); |
| 176 |
bench_setup_points(user_data, |
| 177 |
"139380000x-31920000", |
| 178 |
"128452975x503157902", |
| 179 |
GRN_DB_WGS84_GEO_POINT); |
| 180 |
data->geo_distance_proc = GET(data->context, "geo_distance"); |
| 181 |
} |
| 182 |
|
| 183 |
static void |
| 184 |
bench_setup_rectangular_wgs84_1st_to_3rd_quadrant_short(gpointer user_data) |
| 185 |
{ |
| 186 |
BenchmarkData *data = user_data; |
| 187 |
|
| 188 |
bench_setup_common(user_data); |
| 189 |
bench_setup_points(user_data, |
| 190 |
"128452975x503157902", |
| 191 |
"-56880000x-172310000", |
| 192 |
GRN_DB_WGS84_GEO_POINT); |
| 193 |
data->geo_distance_proc = GET(data->context, "geo_distance"); |
| 194 |
} |
| 195 |
|
| 196 |
static void |
| 197 |
bench_setup_rectangular_wgs84_3rd_to_1st_quadrant_short(gpointer user_data) |
| 198 |
{ |
| 199 |
BenchmarkData *data = user_data; |
| 200 |
|
| 201 |
bench_setup_common(user_data); |
| 202 |
bench_setup_points(user_data, |
| 203 |
"-56880000x-172310000", |
| 204 |
"128452975x503157902", |
| 205 |
GRN_DB_WGS84_GEO_POINT); |
| 206 |
data->geo_distance_proc = GET(data->context, "geo_distance"); |
| 207 |
} |
| 208 |
|
| 209 |
static void |
| 210 |
bench_setup_rectangular_wgs84_1st_to_4th_quadrant_short(gpointer user_data) |
| 211 |
{ |
| 212 |
BenchmarkData *data = user_data; |
| 213 |
|
| 214 |
bench_setup_common(user_data); |
| 215 |
bench_setup_points(user_data, |
| 216 |
"128452975x503157902", |
| 217 |
"-122100000x66300000", |
| 218 |
GRN_DB_WGS84_GEO_POINT); |
| 219 |
data->geo_distance_proc = GET(data->context, "geo_distance"); |
| 220 |
} |
| 221 |
|
| 222 |
static void |
| 223 |
bench_setup_rectangular_wgs84_4th_to_1st_quadrant_short(gpointer user_data) |
| 224 |
{ |
| 225 |
BenchmarkData *data = user_data; |
| 226 |
|
| 227 |
bench_setup_common(user_data); |
| 228 |
bench_setup_points(user_data, |
| 229 |
"-122100000x66300000", |
| 230 |
"128452975x503157902", |
| 231 |
GRN_DB_WGS84_GEO_POINT); |
| 232 |
data->geo_distance_proc = GET(data->context, "geo_distance"); |
| 233 |
} |
| 234 |
|
| 235 |
static void |
| 236 |
bench_setup_rectangular_wgs84_2nd_to_4th_quadrant_short(gpointer user_data) |
| 237 |
{ |
| 238 |
BenchmarkData *data = user_data; |
| 239 |
|
| 240 |
bench_setup_common(user_data); |
| 241 |
bench_setup_points(user_data, |
| 242 |
"139380000x-31920000", |
| 243 |
"-122100000x66300000", |
| 244 |
GRN_DB_WGS84_GEO_POINT); |
| 245 |
data->geo_distance_proc = GET(data->context, "geo_distance"); |
| 246 |
} |
| 247 |
|
| 248 |
static void |
| 249 |
bench_setup_rectangular_wgs84_4th_to_2nd_quadrant_short(gpointer user_data) |
| 250 |
{ |
| 251 |
BenchmarkData *data = user_data; |
| 252 |
|
| 253 |
bench_setup_common(user_data); |
| 254 |
bench_setup_points(user_data, |
| 255 |
"-122100000x66300000", |
| 256 |
"139380000x-31920000", |
| 257 |
GRN_DB_WGS84_GEO_POINT); |
| 258 |
data->geo_distance_proc = GET(data->context, "geo_distance"); |
| 259 |
} |
| 260 |
|
| 261 |
static void |
| 262 |
bench_setup_rectangular_wgs84_1st_to_2nd_quadrant_long(gpointer user_data) |
| 263 |
{ |
| 264 |
BenchmarkData *data = user_data; |
| 265 |
|
| 266 |
bench_setup_common(user_data); |
| 267 |
bench_setup_points(user_data, |
| 268 |
"128452975x503157902", |
| 269 |
"135960000x-440760000", |
| 270 |
GRN_DB_WGS84_GEO_POINT); |
| 271 |
data->geo_distance_proc = GET(data->context, "geo_distance"); |
| 272 |
} |
| 273 |
|
| 274 |
static void |
| 275 |
bench_setup_rectangular_wgs84_2nd_to_1st_quadrant_long(gpointer user_data) |
| 276 |
{ |
| 277 |
BenchmarkData *data = user_data; |
| 278 |
|
| 279 |
bench_setup_common(user_data); |
| 280 |
bench_setup_points(user_data, |
| 281 |
"135960000x-440760000", |
| 282 |
"128452975x503157902", |
| 283 |
GRN_DB_WGS84_GEO_POINT); |
| 284 |
data->geo_distance_proc = GET(data->context, "geo_distance"); |
| 285 |
} |
| 286 |
|
| 287 |
static void |
| 288 |
bench_setup_rectangular_wgs84_2nd_to_3rd_quadrant_short(gpointer user_data) |
| 289 |
{ |
| 290 |
BenchmarkData *data = user_data; |
| 291 |
|
| 292 |
bench_setup_common(user_data); |
| 293 |
bench_setup_points(user_data, |
| 294 |
"135960000x-440760000", |
| 295 |
"-56880000x-172310000", |
| 296 |
GRN_DB_WGS84_GEO_POINT); |
| 297 |
data->geo_distance_proc = GET(data->context, "geo_distance"); |
| 298 |
} |
| 299 |
|
| 300 |
static void |
| 301 |
bench_setup_rectangular_wgs84_3rd_to_2nd_quadrant_short(gpointer user_data) |
| 302 |
{ |
| 303 |
BenchmarkData *data = user_data; |
| 304 |
|
| 305 |
bench_setup_common(user_data); |
| 306 |
bench_setup_points(user_data, |
| 307 |
"-56880000x-172310000", |
| 308 |
"135960000x-440760000", |
| 309 |
GRN_DB_WGS84_GEO_POINT); |
| 310 |
data->geo_distance_proc = GET(data->context, "geo_distance"); |
| 311 |
} |
| 312 |
|
| 313 |
static void |
| 314 |
bench_setup_rectangular_wgs84_3rd_to_4th_quadrant_short(gpointer user_data) |
| 315 |
{ |
| 316 |
BenchmarkData *data = user_data; |
| 317 |
|
| 318 |
bench_setup_common(user_data); |
| 319 |
bench_setup_points(user_data, |
| 320 |
"-56880000x-172310000", |
| 321 |
"-122100000x66300000", |
| 322 |
GRN_DB_WGS84_GEO_POINT); |
| 323 |
data->geo_distance_proc = GET(data->context, "geo_distance"); |
| 324 |
} |
| 325 |
|
| 326 |
static void |
| 327 |
bench_setup_rectangular_wgs84_4th_to_3rd_quadrant_short(gpointer user_data) |
| 328 |
{ |
| 329 |
BenchmarkData *data = user_data; |
| 330 |
|
| 331 |
bench_setup_common(user_data); |
| 332 |
bench_setup_points(user_data, |
| 333 |
"-122100000x66300000", |
| 334 |
"-56880000x-172310000", |
| 335 |
GRN_DB_WGS84_GEO_POINT); |
| 336 |
data->geo_distance_proc = GET(data->context, "geo_distance"); |
| 337 |
} |
| 338 |
|
| 339 |
static void |
| 340 |
bench_setup_rectangular_wgs84_3rd_to_4th_quadrant_long(gpointer user_data) |
| 341 |
{ |
| 342 |
BenchmarkData *data = user_data; |
| 343 |
|
| 344 |
bench_setup_common(user_data); |
| 345 |
bench_setup_points(user_data, |
| 346 |
"-56880000x-172310000", |
| 347 |
"-121926000x544351000", |
| 348 |
GRN_DB_WGS84_GEO_POINT); |
| 349 |
data->geo_distance_proc = GET(data->context, "geo_distance"); |
| 350 |
} |
| 351 |
|
| 352 |
static void |
| 353 |
bench_setup_rectangular_wgs84_4th_to_3rd_quadrant_long(gpointer user_data) |
| 354 |
{ |
| 355 |
BenchmarkData *data = user_data; |
| 356 |
|
| 357 |
bench_setup_common(user_data); |
| 358 |
bench_setup_points(user_data, |
| 359 |
"-121926000x544351000", |
| 360 |
"-56880000x-172310000", |
| 361 |
GRN_DB_WGS84_GEO_POINT); |
| 362 |
data->geo_distance_proc = GET(data->context, "geo_distance"); |
| 363 |
} |
| 364 |
|
| 365 |
static void |
| 366 |
bench_setup_spherical_wgs84(gpointer user_data) |
| 367 |
{ |
| 368 |
BenchmarkData *data = user_data; |
| 369 |
|
| 370 |
bench_setup_wgs84(user_data); |
| 371 |
data->geo_distance_proc = GET(data->context, "geo_distance2"); |
| 372 |
} |
| 373 |
|
| 374 |
static void |
| 375 |
bench_setup_spherical_tgs(gpointer user_data) |
| 376 |
{ |
| 377 |
BenchmarkData *data = user_data; |
| 378 |
|
| 379 |
bench_setup_tgs(user_data); |
| 380 |
data->geo_distance_proc = GET(data->context, "geo_distance2"); |
| 381 |
} |
| 382 |
|
| 383 |
static void |
| 384 |
bench_setup_hubeny_wgs84(gpointer user_data) |
| 385 |
{ |
| 386 |
BenchmarkData *data = user_data; |
| 387 |
|
| 388 |
bench_setup_wgs84(user_data); |
| 389 |
data->geo_distance_proc = GET(data->context, "geo_distance3"); |
| 390 |
} |
| 391 |
|
| 392 |
static void |
| 393 |
bench_setup_hubeny_tgs(gpointer user_data) |
| 394 |
{ |
| 395 |
BenchmarkData *data = user_data; |
| 396 |
|
| 397 |
bench_setup_tgs(user_data); |
| 398 |
data->geo_distance_proc = GET(data->context, "geo_distance3"); |
| 399 |
} |
| 400 |
|
| 401 |
static void |
| 402 |
bench_teardown(gpointer user_data) |
| 403 |
{ |
| 404 |
BenchmarkData *data = user_data; |
| 405 |
|
| 406 |
if (data->report_result) { |
| 407 |
grn_obj *result; |
| 408 |
result = grn_expr_get_value(data->context, data->expression, 0); |
| 409 |
g_print("result: %g\n", GRN_FLOAT_VALUE(result)); |
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
} |
| 414 |
|
| 415 |
grn_obj_unlink(data->context, data->end_point); |
| 416 |
grn_obj_unlink(data->context, data->start_point); |
| 417 |
grn_obj_unlink(data->context, data->expression); |
| 418 |
grn_obj_unlink(data->context, data->database); |
| 419 |
grn_ctx_fin(data->context); |
| 420 |
} |
| 421 |
|
| 422 |
int |
| 423 |
main(int argc, gchar **argv) |
| 424 |
{ |
| 425 |
grn_rc rc; |
| 426 |
BenchmarkData data; |
| 427 |
BenchReporter *reporter; |
| 428 |
gint n = 1000; |
| 429 |
|
| 430 |
rc = grn_init(); |
| 431 |
if (rc != GRN_SUCCESS) { |
| 432 |
g_print("failed to initialize Groonga: <%d>: %s\n", |
| 433 |
rc, grn_get_global_error_message()); |
| 434 |
return EXIT_FAILURE; |
| 435 |
} |
| 436 |
bench_init(&argc, &argv); |
| 437 |
|
| 438 |
data.report_result = g_getenv("GROONGA_BENCH_REPORT_RESULT") != NULL; |
| 439 |
data.context = g_new(grn_ctx, 1); |
| 440 |
|
| 441 |
{ |
| 442 |
const gchar *groonga_bench_n; |
| 443 |
groonga_bench_n = g_getenv("GROONGA_BENCH_N"); |
| 444 |
if (groonga_bench_n) { |
| 445 |
n = atoi(groonga_bench_n); |
| 446 |
} |
| 447 |
} |
| 448 |
|
| 449 |
reporter = bench_reporter_new(); |
| 450 |
|
| 451 |
#define REGISTER(label, setup) \ |
| 452 |
bench_reporter_register(reporter, label, n, \ |
| 453 |
bench_setup_ ## setup, \ |
| 454 |
bench_geo_distance, \ |
| 455 |
bench_teardown, \ |
| 456 |
&data) |
| 457 |
REGISTER("rectangular (WGS84)", rectangular_wgs84); |
| 458 |
REGISTER("rectangular (TOKYO)", rectangular_tgs); |
| 459 |
REGISTER("rectangular (WGS84 Tokyo to Lisbon)", |
| 460 |
rectangular_wgs84_1st_to_2nd_quadrant_short); |
| 461 |
REGISTER("rectangular (WGS84 Lisbon to Tokyo)", |
| 462 |
rectangular_wgs84_2nd_to_1st_quadrant_short); |
| 463 |
REGISTER("rectangular (WGS84 Tokyo to San Francisco)", |
| 464 |
rectangular_wgs84_1st_to_2nd_quadrant_long); |
| 465 |
REGISTER("rectangular (WGS84 San Francisco to Tokyo)", |
| 466 |
rectangular_wgs84_2nd_to_1st_quadrant_long); |
| 467 |
REGISTER("rectangular (WGS84 Brasplia to Cape Town)", |
| 468 |
rectangular_wgs84_3rd_to_4th_quadrant_short); |
| 469 |
REGISTER("rectangular (WGS84 Cape Town to Brasplia)", |
| 470 |
rectangular_wgs84_4th_to_3rd_quadrant_short); |
| 471 |
REGISTER("rectangular (WGS84 Brasplia to Sydney)", |
| 472 |
rectangular_wgs84_3rd_to_4th_quadrant_long); |
| 473 |
REGISTER("rectangular (WGS84 Sydney to Brasplia)", |
| 474 |
rectangular_wgs84_4th_to_3rd_quadrant_long); |
| 475 |
REGISTER("rectangular (WGS84 Tokyo to Brasplia)", |
| 476 |
rectangular_wgs84_1st_to_4th_quadrant_short); |
| 477 |
REGISTER("rectangular (WGS84 Brasplia to Tokyo)", |
| 478 |
rectangular_wgs84_4th_to_1st_quadrant_short); |
| 479 |
REGISTER("rectangular (WGS84 Lisbon to Cape Town)", |
| 480 |
rectangular_wgs84_2nd_to_3rd_quadrant_short); |
| 481 |
REGISTER("rectangular (WGS84 Cape Town to Lisbon)", |
| 482 |
rectangular_wgs84_3rd_to_2nd_quadrant_short); |
| 483 |
REGISTER("rectangular (WGS84 Tokyo to Cape Town)", |
| 484 |
rectangular_wgs84_1st_to_3rd_quadrant_short); |
| 485 |
REGISTER("rectangular (WGS84 Cape Town to Tokyo)", |
| 486 |
rectangular_wgs84_3rd_to_1st_quadrant_short); |
| 487 |
REGISTER("rectangular (WGS84 Lisbon to Cape Town)", |
| 488 |
rectangular_wgs84_2nd_to_4th_quadrant_short); |
| 489 |
REGISTER("rectangular (WGS84 Cape Town to Lisbon)", |
| 490 |
rectangular_wgs84_4th_to_2nd_quadrant_short); |
| 491 |
REGISTER("spherical (WGS84)", spherical_wgs84); |
| 492 |
REGISTER("spherical (TOKYO)", spherical_tgs); |
| 493 |
REGISTER("hubeny (WGS84)", hubeny_wgs84); |
| 494 |
REGISTER("hubeny (TOKYO)", hubeny_tgs); |
| 495 |
#undef REGISTER |
| 496 |
|
| 497 |
bench_reporter_run(reporter); |
| 498 |
g_object_unref(reporter); |
| 499 |
|
| 500 |
g_free(data.context); |
| 501 |
|
| 502 |
bench_quit(); |
| 503 |
grn_fin(); |
| 504 |
|
| 505 |
return EXIT_SUCCESS; |
| 506 |
} |