Navigation Menu

Skip to content

Commit

Permalink
Add a benchmark for result set
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Oct 6, 2015
1 parent f27fa66 commit d39667f
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -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
Expand Down
13 changes: 11 additions & 2 deletions benchmark/Makefile.am
Expand Up @@ -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 = \
Expand Down Expand Up @@ -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 $@:
Expand Down Expand Up @@ -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)
139 changes: 139 additions & 0 deletions benchmark/bench-result-set.c
@@ -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;
}

0 comments on commit d39667f

Please sign in to comment.