File: bench-result-set-raw.c

package info (click to toggle)
groonga 15.2.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 171,500 kB
  • sloc: ansic: 772,536; cpp: 51,530; ruby: 40,538; javascript: 10,250; yacc: 7,045; sh: 5,622; python: 2,821; makefile: 1,677
file content (71 lines) | stat: -rw-r--r-- 2,267 bytes parent folder | download | duplicates (2)
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
/*
  Copyright (C) 2015-2019  Sutou Kouhei <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
*/

#include <stdio.h>
#include <stdlib.h>

#include <groonga.h>

int
main(int argc, char **argv)
{
  grn_rc rc;
  grn_ctx ctx;
  int n = 10000000;

  rc = grn_init();
  if (rc != GRN_SUCCESS) {
    printf("failed to initialize Groonga: <%d>: %s\n",
           rc, grn_get_global_error_message());
    return EXIT_FAILURE;
  }

  grn_ctx_init(&ctx, 0);
  grn_obj *db = grn_db_open(&ctx, "db/db");
  if (ctx.rc != GRN_SUCCESS) {
    printf("failed to open database: <%d>: %s\n",
           rc, grn_get_global_error_message());
    return EXIT_FAILURE;
  }

  grn_obj *source_table = grn_ctx_get(&ctx, "Sources", -1);
  grn_obj *result_set = grn_table_create(&ctx,
                                         NULL, 0, NULL,
                                         GRN_TABLE_HASH_KEY | GRN_OBJ_WITH_SUBREC,
                                         source_table,
                                         NULL);
  grn_timeval start;
  grn_timeval_now(&ctx, &start);
  for (int i = 0; i < n; i++) {
    grn_id id = i;
    grn_hash_add(&ctx, (grn_hash *)result_set, &id, sizeof(grn_id), NULL, NULL);
  }
  grn_timeval end;
  grn_timeval_now(&ctx, &end);
  double elapsed =
    (end.tv_sec + (end.tv_nsec / GRN_TIME_NSEC_PER_SEC_F)) -
    (start.tv_sec + (start.tv_nsec / GRN_TIME_NSEC_PER_SEC_F));
  printf("%f:%d\n", elapsed, grn_table_size(&ctx, result_set));
  grn_obj_close(&ctx, result_set);
  grn_obj_close(&ctx, db);
  grn_ctx_fin(&ctx);

  grn_fin();

  return EXIT_SUCCESS;
}