Kouhei Sutou
null+****@clear*****
Thu Mar 30 16:14:23 JST 2017
Kouhei Sutou 2017-03-30 16:14:23 +0900 (Thu, 30 Mar 2017) New Revision: d327e52511f9317d24be3a14cb190dbee7aada95 https://github.com/groonga/groonga/commit/d327e52511f9317d24be3a14cb190dbee7aada95 Message: benchmark cache: add Added files: benchmark/bench-cache.c Modified files: .gitignore benchmark/Makefile.am Modified: .gitignore (+1 -0) =================================================================== --- .gitignore 2017-03-30 16:02:22 +0900 (cce79bc) +++ .gitignore 2017-03-30 16:14:23 +0900 (04ccca2) @@ -107,6 +107,7 @@ CMakeFiles /benchmark/bench-result-set /benchmark/bench-between-sequential /benchmark/bench-nfkc +/benchmark/bench-cache /packages/*/*.log /packages/apt/env.sh /packages/apt/debian/groonga-keyring.postrm Modified: benchmark/Makefile.am (+11 -2) =================================================================== --- benchmark/Makefile.am 2017-03-30 16:02:22 +0900 (bdc4698) +++ benchmark/Makefile.am 2017-03-30 16:14:23 +0900 (a2a8b29) @@ -14,7 +14,8 @@ noinst_PROGRAMS = \ bench-range-select \ bench-result-set \ bench-between-sequential \ - bench-nfkc + bench-nfkc \ + bench-cache endif EXTRA_DIST = \ @@ -64,6 +65,9 @@ nodist_EXTRA_bench_between_sequential_SOURCES = $(NONEXISTENT_CXX_SOURCE) bench_nfkc_SOURCES = bench-nfkc.c nodist_EXTRA_bench_nfkc_SOURCES = $(NONEXISTENT_CXX_SOURCE) +bench_cache_SOURCES = bench-cache.c +nodist_EXTRA_bench_cache_SOURCES = $(NONEXISTENT_CXX_SOURCE) + benchmarks = \ run-bench-table-factory \ run-bench-geo-distance \ @@ -73,7 +77,8 @@ benchmarks = \ run-bench-range-select \ run-bench-result-set \ run-bench-between-sequential \ - run-bench-nfkc + run-bench-nfkc \ + run-bench-cache run-bench-table-factory: bench-table-factory @echo $@: @@ -141,4 +146,8 @@ run-bench-nfkc: bench-nfkc @echo $@: ./bench-nfkc +run-bench-cache: bench-cache + @echo $@: + ./bench-cache + benchmark: $(benchmarks) Added: benchmark/bench-cache.c (+138 -0) 100644 =================================================================== --- /dev/null +++ benchmark/bench-cache.c 2017-03-30 16:14:23 +0900 (b68dcf1) @@ -0,0 +1,138 @@ +/* -*- c-basic-offset: 2; coding: utf-8 -*- */ +/* + Copyright (C) 2017 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 <stdlib.h> +#include <stdio.h> + +#include <grn_cache.h> + +#include "lib/benchmark.h" + +typedef struct _BenchmarkData +{ + grn_ctx *context; + grn_cache *cache; + grn_obj value; +} BenchmarkData; + +static void +bench_n(BenchmarkData *data, gint64 n) +{ + gint64 i; + grn_ctx *ctx; + grn_cache *cache; + grn_obj *value; + grn_obj fetch_buffer; + + ctx = data->context; + cache = data->cache; + value = &(data->value); + GRN_TEXT_INIT(&fetch_buffer, 0); + for (i = 0; i < n; i++) { + char key[GRN_TABLE_MAX_KEY_SIZE]; + grn_snprintf(key, + GRN_TABLE_MAX_KEY_SIZE, + GRN_TABLE_MAX_KEY_SIZE, + "key:%" GRN_FMT_INT64D, + i); + GRN_BULK_REWIND(&fetch_buffer); + grn_cache_fetch(ctx, cache, key, strlen(key), &fetch_buffer); + grn_cache_update(ctx, cache, key, strlen(key), value); + } + GRN_OBJ_FIN(ctx, &fetch_buffer); +} + +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_setup(gpointer user_data) +{ + BenchmarkData *data = user_data; + + data->cache = grn_cache_open(data->context); + GRN_TEXT_INIT(&(data->value), 0); + while (GRN_TEXT_LEN(&(data->value)) < 1024) { + GRN_TEXT_PUTS(data->context, &(data->value), "XXXXXXXXXXX"); + } +} + +static void +bench_teardown(gpointer user_data) +{ + BenchmarkData *data = user_data; + + grn_obj_close(data->context, &(data->value)); + grn_cache_close(data->context, data->cache); +} + +int +main(int argc, gchar **argv) +{ + grn_rc rc; + BenchmarkData data; + BenchReporter *reporter; + gchar *base_dir; + grn_ctx ctx; + gint n = 100; + + 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); + + grn_ctx_init(&ctx, 0); + + data.context = &ctx; + + base_dir = g_build_filename(g_get_tmp_dir(), "groonga-bench", NULL); + bench_utils_remove_path_recursive_force(base_dir); + g_mkdir_with_parents(base_dir, 0755); + + 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_run(reporter); + g_object_unref(reporter); + + grn_ctx_fin(&ctx); + + bench_utils_remove_path_recursive_force(base_dir); + + bench_quit(); + grn_fin(); + + return EXIT_SUCCESS; +} -------------- next part -------------- HTML����������������������������...Download