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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 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 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
|
/*
Copyright (C) 2009-2016 Kouhei Sutou <kou@clear-code.com>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
groonga: 3ad91b868909444f66a36dbcbdbe2292ed14bd72
CFLAGS: -O0 -g
CPU: AMD Athlon(tm) 64 Processor 3000+
% test/benchmark/bench-geo-distance
(time)
rectangular (WGS84): (0.0813662)
rectangular (TOKYO): (0.0621928)
spherical (WGS84): (0.0760155)
spherical (TOKYO): (0.0660843)
hubeny (WGS84): (0.110684)
hubeny (TOKYO): (0.0702277)
% test/benchmark/bench-geo-distance
(time)
rectangular (WGS84): (0.0742154)
rectangular (TOKYO): (0.0816863)
spherical (WGS84): (0.074316)
spherical (TOKYO): (0.0696254)
hubeny (WGS84): (0.0650147)
hubeny (TOKYO): (0.0644057)
% test/benchmark/bench-geo-distance
(time)
rectangular (WGS84): (0.0781161)
rectangular (TOKYO): (0.0706679)
spherical (WGS84): (0.075739)
spherical (TOKYO): (0.0809402)
hubeny (WGS84): (0.0727023)
hubeny (TOKYO): (0.0718146)
*/
#include <string.h>
#include <stdlib.h>
#include <grn_db.h>
#include <groonga.h>
#include "lib/benchmark.h"
#define GET(context, name) (grn_ctx_get(context, name, strlen(name)))
grn_obj *grn_expr_get_value(grn_ctx *ctx, grn_obj *expr, int offset);
typedef struct _BenchmarkData
{
gchar *base_dir;
gboolean report_result;
grn_ctx *context;
grn_obj *database;
grn_obj *geo_distance_proc;
grn_obj *expression;
grn_obj *start_point;
grn_obj *end_point;
} BenchmarkData;
static void
bench_geo_distance(gpointer user_data)
{
BenchmarkData *data = user_data;
grn_proc_call(data->context, data->geo_distance_proc,
2, data->expression);
}
static void
bench_setup_common(gpointer user_data)
{
BenchmarkData *data = user_data;
grn_ctx_init(data->context, GRN_CTX_USE_QL);
data->database = grn_db_create(data->context, NULL, NULL);
data->expression = grn_expr_create(data->context, NULL, 0);
}
static void
bench_setup_points(gpointer user_data,
const gchar *start_point_string,
const gchar *end_point_string,
grn_builtin_type wgs84_or_tgs)
{
BenchmarkData *data = user_data;
grn_obj start_point_text, end_point_text;
GRN_TEXT_INIT(&start_point_text, 0);
GRN_TEXT_INIT(&end_point_text, 0);
GRN_TEXT_SETS(data->context, &start_point_text, start_point_string);
GRN_TEXT_SETS(data->context, &end_point_text, end_point_string);
data->start_point = grn_obj_open(data->context, GRN_BULK, 0, wgs84_or_tgs);
data->end_point = grn_obj_open(data->context, GRN_BULK, 0, wgs84_or_tgs);
grn_obj_cast(data->context, &start_point_text, data->start_point, false);
grn_obj_cast(data->context, &end_point_text, data->end_point, false);
grn_ctx_push(data->context, data->start_point);
grn_ctx_push(data->context, data->end_point);
grn_obj_unlink(data->context, &start_point_text);
grn_obj_unlink(data->context, &end_point_text);
}
static void
bench_setup_wgs84(gpointer user_data)
{
bench_setup_common(user_data);
bench_setup_points(user_data,
"127980000x502560000",
"128880000x503640000",
GRN_DB_WGS84_GEO_POINT);
}
static void
bench_setup_tgs(gpointer user_data)
{
bench_setup_common(user_data);
bench_setup_points(user_data,
"127980000x502560000",
"128880000x503640000",
GRN_DB_TOKYO_GEO_POINT);
}
static void
bench_setup_rectangular_wgs84(gpointer user_data)
{
BenchmarkData *data = user_data;
bench_setup_wgs84(user_data);
data->geo_distance_proc = GET(data->context, "geo_distance");
}
static void
bench_setup_rectangular_tgs(gpointer user_data)
{
BenchmarkData *data = user_data;
bench_setup_tgs(user_data);
data->geo_distance_proc = GET(data->context, "geo_distance");
}
static void
bench_setup_rectangular_wgs84_1st_to_2nd_quadrant_short(gpointer user_data)
{
BenchmarkData *data = user_data;
bench_setup_common(user_data);
bench_setup_points(user_data,
"128452975x503157902",
"139380000x-31920000",
GRN_DB_WGS84_GEO_POINT);
data->geo_distance_proc = GET(data->context, "geo_distance");
}
static void
bench_setup_rectangular_wgs84_2nd_to_1st_quadrant_short(gpointer user_data)
{
BenchmarkData *data = user_data;
bench_setup_common(user_data);
bench_setup_points(user_data,
"139380000x-31920000",
"128452975x503157902",
GRN_DB_WGS84_GEO_POINT);
data->geo_distance_proc = GET(data->context, "geo_distance");
}
static void
bench_setup_rectangular_wgs84_1st_to_3rd_quadrant_short(gpointer user_data)
{
BenchmarkData *data = user_data;
bench_setup_common(user_data);
bench_setup_points(user_data,
"128452975x503157902",
"-56880000x-172310000",
GRN_DB_WGS84_GEO_POINT);
data->geo_distance_proc = GET(data->context, "geo_distance");
}
static void
bench_setup_rectangular_wgs84_3rd_to_1st_quadrant_short(gpointer user_data)
{
BenchmarkData *data = user_data;
bench_setup_common(user_data);
bench_setup_points(user_data,
"-56880000x-172310000",
"128452975x503157902",
GRN_DB_WGS84_GEO_POINT);
data->geo_distance_proc = GET(data->context, "geo_distance");
}
static void
bench_setup_rectangular_wgs84_1st_to_4th_quadrant_short(gpointer user_data)
{
BenchmarkData *data = user_data;
bench_setup_common(user_data);
bench_setup_points(user_data,
"128452975x503157902",
"-122100000x66300000",
GRN_DB_WGS84_GEO_POINT);
data->geo_distance_proc = GET(data->context, "geo_distance");
}
static void
bench_setup_rectangular_wgs84_4th_to_1st_quadrant_short(gpointer user_data)
{
BenchmarkData *data = user_data;
bench_setup_common(user_data);
bench_setup_points(user_data,
"-122100000x66300000",
"128452975x503157902",
GRN_DB_WGS84_GEO_POINT);
data->geo_distance_proc = GET(data->context, "geo_distance");
}
static void
bench_setup_rectangular_wgs84_2nd_to_4th_quadrant_short(gpointer user_data)
{
BenchmarkData *data = user_data;
bench_setup_common(user_data);
bench_setup_points(user_data,
"139380000x-31920000",
"-122100000x66300000",
GRN_DB_WGS84_GEO_POINT);
data->geo_distance_proc = GET(data->context, "geo_distance");
}
static void
bench_setup_rectangular_wgs84_4th_to_2nd_quadrant_short(gpointer user_data)
{
BenchmarkData *data = user_data;
bench_setup_common(user_data);
bench_setup_points(user_data,
"-122100000x66300000",
"139380000x-31920000",
GRN_DB_WGS84_GEO_POINT);
data->geo_distance_proc = GET(data->context, "geo_distance");
}
static void
bench_setup_rectangular_wgs84_1st_to_2nd_quadrant_long(gpointer user_data)
{
BenchmarkData *data = user_data;
bench_setup_common(user_data);
bench_setup_points(user_data,
"128452975x503157902",
"135960000x-440760000",
GRN_DB_WGS84_GEO_POINT);
data->geo_distance_proc = GET(data->context, "geo_distance");
}
static void
bench_setup_rectangular_wgs84_2nd_to_1st_quadrant_long(gpointer user_data)
{
BenchmarkData *data = user_data;
bench_setup_common(user_data);
bench_setup_points(user_data,
"135960000x-440760000",
"128452975x503157902",
GRN_DB_WGS84_GEO_POINT);
data->geo_distance_proc = GET(data->context, "geo_distance");
}
static void
bench_setup_rectangular_wgs84_2nd_to_3rd_quadrant_short(gpointer user_data)
{
BenchmarkData *data = user_data;
bench_setup_common(user_data);
bench_setup_points(user_data,
"135960000x-440760000",
"-56880000x-172310000",
GRN_DB_WGS84_GEO_POINT);
data->geo_distance_proc = GET(data->context, "geo_distance");
}
static void
bench_setup_rectangular_wgs84_3rd_to_2nd_quadrant_short(gpointer user_data)
{
BenchmarkData *data = user_data;
bench_setup_common(user_data);
bench_setup_points(user_data,
"-56880000x-172310000",
"135960000x-440760000",
GRN_DB_WGS84_GEO_POINT);
data->geo_distance_proc = GET(data->context, "geo_distance");
}
static void
bench_setup_rectangular_wgs84_3rd_to_4th_quadrant_short(gpointer user_data)
{
BenchmarkData *data = user_data;
bench_setup_common(user_data);
bench_setup_points(user_data,
"-56880000x-172310000",
"-122100000x66300000",
GRN_DB_WGS84_GEO_POINT);
data->geo_distance_proc = GET(data->context, "geo_distance");
}
static void
bench_setup_rectangular_wgs84_4th_to_3rd_quadrant_short(gpointer user_data)
{
BenchmarkData *data = user_data;
bench_setup_common(user_data);
bench_setup_points(user_data,
"-122100000x66300000",
"-56880000x-172310000",
GRN_DB_WGS84_GEO_POINT);
data->geo_distance_proc = GET(data->context, "geo_distance");
}
static void
bench_setup_rectangular_wgs84_3rd_to_4th_quadrant_long(gpointer user_data)
{
BenchmarkData *data = user_data;
bench_setup_common(user_data);
bench_setup_points(user_data,
"-56880000x-172310000",
"-121926000x544351000",
GRN_DB_WGS84_GEO_POINT);
data->geo_distance_proc = GET(data->context, "geo_distance");
}
static void
bench_setup_rectangular_wgs84_4th_to_3rd_quadrant_long(gpointer user_data)
{
BenchmarkData *data = user_data;
bench_setup_common(user_data);
bench_setup_points(user_data,
"-121926000x544351000",
"-56880000x-172310000",
GRN_DB_WGS84_GEO_POINT);
data->geo_distance_proc = GET(data->context, "geo_distance");
}
static void
bench_setup_spherical_wgs84(gpointer user_data)
{
BenchmarkData *data = user_data;
bench_setup_wgs84(user_data);
data->geo_distance_proc = GET(data->context, "geo_distance2");
}
static void
bench_setup_spherical_tgs(gpointer user_data)
{
BenchmarkData *data = user_data;
bench_setup_tgs(user_data);
data->geo_distance_proc = GET(data->context, "geo_distance2");
}
static void
bench_setup_hubeny_wgs84(gpointer user_data)
{
BenchmarkData *data = user_data;
bench_setup_wgs84(user_data);
data->geo_distance_proc = GET(data->context, "geo_distance3");
}
static void
bench_setup_hubeny_tgs(gpointer user_data)
{
BenchmarkData *data = user_data;
bench_setup_tgs(user_data);
data->geo_distance_proc = GET(data->context, "geo_distance3");
}
static void
bench_teardown(gpointer user_data)
{
BenchmarkData *data = user_data;
if (data->report_result) {
grn_obj *result;
result = grn_expr_get_value(data->context, data->expression, 0);
g_print("result: %g\n", GRN_FLOAT_VALUE(result));
/* http://vldb.gsi.go.jp/ says '38820.79' in WGS84 and
'38816.42' in Tokyo geodetic system for a distance
between '127980000x502560000' and '128880000x503640000'. */
}
grn_obj_unlink(data->context, data->end_point);
grn_obj_unlink(data->context, data->start_point);
grn_obj_unlink(data->context, data->expression);
grn_obj_unlink(data->context, data->database);
grn_ctx_fin(data->context);
}
int
main(int argc, gchar **argv)
{
grn_rc rc;
BenchmarkData data;
BenchReporter *reporter;
gint n = 1000;
rc = grn_init();
if (rc != GRN_SUCCESS) {
g_print("failed to initialize Groonga: <%d>: %s\n",
rc, grn_get_global_error_message());
return EXIT_FAILURE;
}
bench_init(&argc, &argv);
data.report_result = g_getenv("GROONGA_BENCH_REPORT_RESULT") != NULL;
data.context = g_new(grn_ctx, 1);
{
const gchar *groonga_bench_n;
groonga_bench_n = g_getenv("GROONGA_BENCH_N");
if (groonga_bench_n) {
n = atoi(groonga_bench_n);
}
}
reporter = bench_reporter_new();
#define REGISTER(label, setup) \
bench_reporter_register(reporter, label, n, \
bench_setup_ ## setup, \
bench_geo_distance, \
bench_teardown, \
&data)
REGISTER("rectangular (WGS84)", rectangular_wgs84);
REGISTER("rectangular (TOKYO)", rectangular_tgs);
REGISTER("rectangular (WGS84 Tokyo to Lisbon)",
rectangular_wgs84_1st_to_2nd_quadrant_short);
REGISTER("rectangular (WGS84 Lisbon to Tokyo)",
rectangular_wgs84_2nd_to_1st_quadrant_short);
REGISTER("rectangular (WGS84 Tokyo to San Francisco)",
rectangular_wgs84_1st_to_2nd_quadrant_long);
REGISTER("rectangular (WGS84 San Francisco to Tokyo)",
rectangular_wgs84_2nd_to_1st_quadrant_long);
REGISTER("rectangular (WGS84 Brasplia to Cape Town)",
rectangular_wgs84_3rd_to_4th_quadrant_short);
REGISTER("rectangular (WGS84 Cape Town to Brasplia)",
rectangular_wgs84_4th_to_3rd_quadrant_short);
REGISTER("rectangular (WGS84 Brasplia to Sydney)",
rectangular_wgs84_3rd_to_4th_quadrant_long);
REGISTER("rectangular (WGS84 Sydney to Brasplia)",
rectangular_wgs84_4th_to_3rd_quadrant_long);
REGISTER("rectangular (WGS84 Tokyo to Brasplia)",
rectangular_wgs84_1st_to_4th_quadrant_short);
REGISTER("rectangular (WGS84 Brasplia to Tokyo)",
rectangular_wgs84_4th_to_1st_quadrant_short);
REGISTER("rectangular (WGS84 Lisbon to Cape Town)",
rectangular_wgs84_2nd_to_3rd_quadrant_short);
REGISTER("rectangular (WGS84 Cape Town to Lisbon)",
rectangular_wgs84_3rd_to_2nd_quadrant_short);
REGISTER("rectangular (WGS84 Tokyo to Cape Town)",
rectangular_wgs84_1st_to_3rd_quadrant_short);
REGISTER("rectangular (WGS84 Cape Town to Tokyo)",
rectangular_wgs84_3rd_to_1st_quadrant_short);
REGISTER("rectangular (WGS84 Lisbon to Cape Town)",
rectangular_wgs84_2nd_to_4th_quadrant_short);
REGISTER("rectangular (WGS84 Cape Town to Lisbon)",
rectangular_wgs84_4th_to_2nd_quadrant_short);
REGISTER("spherical (WGS84)", spherical_wgs84);
REGISTER("spherical (TOKYO)", spherical_tgs);
REGISTER("hubeny (WGS84)", hubeny_wgs84);
REGISTER("hubeny (TOKYO)", hubeny_tgs);
#undef REGISTER
bench_reporter_run(reporter);
g_object_unref(reporter);
g_free(data.context);
bench_quit();
grn_fin();
return EXIT_SUCCESS;
}
|