Debian Codegraph @

benchmark/bench-result-set-raw.c

raw symbols SCIP
1 /*
2 Copyright (C) 2015-2019 Sutou Kouhei <[email protected]>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21
22 #include <groonga.h>
23
24 int
25 main(int argc, char **argv)
26 {
27 grn_rc rc;
28 grn_ctx ctx;
29 int n = 10000000;
30
31 rc = grn_init();
32 if (rc != GRN_SUCCESS) {
33 printf("failed to initialize Groonga: <%d>: %s\n",
34 rc, grn_get_global_error_message());
35 return EXIT_FAILURE;
36 }
37
38 grn_ctx_init(&ctx, 0);
39 grn_obj *db = grn_db_open(&ctx, "db/db");
40 if (ctx.rc != GRN_SUCCESS) {
41 printf("failed to open database: <%d>: %s\n",
42 rc, grn_get_global_error_message());
43 return EXIT_FAILURE;
44 }
45
46 grn_obj *source_table = grn_ctx_get(&ctx, "Sources", -1);
47 grn_obj *result_set = grn_table_create(&ctx,
48 NULL, 0, NULL,
49 GRN_TABLE_HASH_KEY | GRN_OBJ_WITH_SUBREC,
50 source_table,
51 NULL);
52 grn_timeval start;
53 grn_timeval_now(&ctx, &start);
54 for (int i = 0; i < n; i++) {
55 grn_id id = i;
56 grn_hash_add(&ctx, (grn_hash *)result_set, &id, sizeof(grn_id), NULL, NULL);
57 }
58 grn_timeval end;
59 grn_timeval_now(&ctx, &end);
60 double elapsed =
61 (end.tv_sec + (end.tv_nsec / GRN_TIME_NSEC_PER_SEC_F)) -
62 (start.tv_sec + (start.tv_nsec / GRN_TIME_NSEC_PER_SEC_F));
63 printf("%f:%d\n", elapsed, grn_table_size(&ctx, result_set));
64 grn_obj_close(&ctx, result_set);
65 grn_obj_close(&ctx, db);
66 grn_ctx_fin(&ctx);
67
68 grn_fin();
69
70 return EXIT_SUCCESS;
71 }