Kouhei Sutou
null+****@clear*****
Tue Oct 6 19:23:56 JST 2015
Kouhei Sutou 2015-10-06 19:23:56 +0900 (Tue, 06 Oct 2015) New Revision: d39667f954e4f61e3d72114f801c2c9cc83b966f https://github.com/groonga/groonga/commit/d39667f954e4f61e3d72114f801c2c9cc83b966f Message: Add a benchmark for result set Added files: benchmark/bench-result-set.c Modified files: .gitignore benchmark/Makefile.am Modified: .gitignore (+1 -0) =================================================================== --- .gitignore 2015-10-06 17:10:45 +0900 (bc3a4eb) +++ .gitignore 2015-10-06 19:23:56 +0900 (6a898a3) @@ -102,6 +102,7 @@ CMakeFiles /benchmark/bench-ctx-create /benchmark/bench-query-optimizer /benchmark/bench-range-select +/benchmark/bench-result-set /packages/*/*.log /packages/apt/env.sh /packages/apt/debian/groonga-keyring.postrm Modified: benchmark/Makefile.am (+11 -2) =================================================================== --- benchmark/Makefile.am 2015-10-06 17:10:45 +0900 (310fb45) +++ benchmark/Makefile.am 2015-10-06 19:23:56 +0900 (20cbc8d) @@ -11,7 +11,8 @@ noinst_PROGRAMS = \ bench-geo-select \ bench-ctx-create \ bench-query-optimizer \ - bench-range-select + bench-range-select \ + bench-result-set endif EXTRA_DIST = \ @@ -50,13 +51,17 @@ nodist_EXTRA_bench_query_optimizer_SOURCES = $(NONEXISTENT_CXX_SOURCE) bench_range_select_SOURCES = bench-range-select.c nodist_EXTRA_bench_range_select_SOURCES = $(NONEXISTENT_CXX_SOURCE) +bench_result_set_SOURCES = bench-result-set.c +nodist_EXTRA_bench_result_set_SOURCES = $(NONEXISTENT_CXX_SOURCE) + benchmarks = \ run-bench-table-factory \ run-bench-geo-distance \ run-bench-geo-select \ run-bench-ctx-create \ run-bench-query-optimizer \ - run-bench-range-select + run-bench-range-select \ + run-bench-result-set run-bench-table-factory: bench-table-factory @echo $@: @@ -99,4 +104,8 @@ run-bench-range-select: bench-range-select GRN_RUBY_SCRIPTS_DIR=$(top_srcdir)/lib/mrb/scripts \ ./bench-range-select +run-bench-result-set: bench-result-set + @echo $@: + ./bench-result-set + benchmark: $(benchmarks) Added: benchmark/bench-result-set.c (+139 -0) 100644 =================================================================== --- /dev/null +++ benchmark/bench-result-set.c 2015-10-06 19:23:56 +0900 (57ae55d) @@ -0,0 +1,139 @@ +/* -*- c-basic-offset: 2; coding: utf-8 -*- */ +/* + Copyright (C) 2015 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 version 2.1 as published by the Free Software Foundation. + + 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 +*/ + +#include <string.h> + +#include <groonga.h> + +#include "lib/benchmark.h" + +typedef struct _BenchmarkData +{ + gchar *base_dir; + grn_ctx *context; + grn_obj *result_set; +} BenchmarkData; + +static void +bench_n(BenchmarkData *data, gint64 n) +{ + gint64 i; + grn_ctx *ctx; + grn_hash *result_set; + + ctx = data->context; + result_set = (grn_hash *)data->result_set; + for (i = 0; i < n; i++) { + grn_id id = i; + grn_hash_add(ctx, result_set, &id, sizeof(grn_id), NULL, NULL); + } +} + +static void +bench_1000(gpointer user_data) +{ + BenchmarkData *data = user_data; + bench_n(data, 1000); +} + +static void +bench_10000(gpointer user_data) +{ + BenchmarkData *data = user_data; + bench_n(data, 10000); +} + +static void +bench_100000(gpointer user_data) +{ + BenchmarkData *data = user_data; + bench_n(data, 100000); +} + +static void +bench_setup(gpointer user_data) +{ + BenchmarkData *data = user_data; + gchar *database_path; + grn_obj *source_table; + const gchar *source_table_name = "Sources"; + + bench_utils_remove_path_recursive_force(data->base_dir); + g_mkdir_with_parents(data->base_dir, 0755); + + grn_ctx_init(data->context, 0); + database_path = g_build_filename(data->base_dir, "db", NULL); + grn_db_create(data->context, database_path, NULL); + g_free(database_path); + + source_table = grn_table_create(data->context, + source_table_name, + strlen(source_table_name), + NULL, + GRN_TABLE_PAT_KEY | GRN_OBJ_PERSISTENT, + grn_ctx_at(data->context, GRN_DB_SHORT_TEXT), + NULL); + data->result_set = grn_table_create(data->context, + NULL, 0, NULL, + GRN_TABLE_HASH_KEY | GRN_OBJ_WITH_SUBREC, + source_table, + NULL); + +} + +static void +bench_teardown(gpointer user_data) +{ + BenchmarkData *data = user_data; + + grn_ctx_fin(data->context); + bench_utils_remove_path_recursive_force(data->base_dir); +} + +int +main(int argc, gchar **argv) +{ + BenchmarkData data; + BenchReporter *reporter; + gint n = 1; + + grn_init(); + bench_init(&argc, &argv); + + data.context = g_new(grn_ctx, 1); + data.base_dir = g_build_filename(g_get_tmp_dir(), "groonga-bench", NULL); + + reporter = bench_reporter_new(); + bench_reporter_register(reporter, "1000", n, + bench_setup, bench_1000, bench_teardown, &data); + bench_reporter_register(reporter, "10000", n, + bench_setup, bench_10000, bench_teardown, &data); + bench_reporter_register(reporter, "100000", n, + bench_setup, bench_100000, bench_teardown, &data); + bench_reporter_run(reporter); + g_object_unref(reporter); + + bench_utils_remove_path_recursive_force(data.base_dir); + + g_free(data.context); + + bench_quit(); + grn_fin(); + + return 0; +} -------------- next part -------------- HTML����������������������������...Download