PostgreSQL Source Code  git master
test_json_parser_perf.c File Reference
#include "postgres_fe.h"
#include "common/jsonapi.h"
#include "common/logging.h"
#include "lib/stringinfo.h"
#include "mb/pg_wchar.h"
#include <stdio.h>
#include <string.h>
Include dependency graph for test_json_parser_perf.c:

Go to the source code of this file.

Macros

#define BUFSIZE   6000
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

◆ BUFSIZE

#define BUFSIZE   6000

Definition at line 32 of file test_json_parser_perf.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 35 of file test_json_parser_perf.c.

36 {
37  char buff[BUFSIZE];
38  FILE *json_file;
39  JsonParseErrorType result;
40  JsonLexContext *lex;
41  StringInfoData json;
42  int n_read;
43  int iter;
44  int use_inc = 0;
45 
46  pg_logging_init(argv[0]);
47 
48  initStringInfo(&json);
49 
50  if (strcmp(argv[1], "-i") == 0)
51  {
52  use_inc = 1;
53  argv++;
54  }
55 
56  sscanf(argv[1], "%d", &iter);
57 
58  if ((json_file = fopen(argv[2], "r")) == NULL)
59  pg_fatal("Could not open input file '%s': %m", argv[2]);
60 
61  while ((n_read = fread(buff, 1, 6000, json_file)) > 0)
62  {
63  appendBinaryStringInfo(&json, buff, n_read);
64  }
65  fclose(json_file);
66  for (int i = 0; i < iter; i++)
67  {
68  if (use_inc)
69  {
70  lex = makeJsonLexContextIncremental(NULL, PG_UTF8, false);
72  json.data, json.len,
73  true);
74  freeJsonLexContext(lex);
75  }
76  else
77  {
78  lex = makeJsonLexContextCstringLen(NULL, json.data, json.len,
79  PG_UTF8, false);
80  result = pg_parse_json(lex, &nullSemAction);
81  freeJsonLexContext(lex);
82  }
83  if (result != JSON_SUCCESS)
84  pg_fatal("unexpected result %d (expecting %d) on parse",
85  result, JSON_SUCCESS);
86  }
87  exit(0);
88 }
int i
Definition: isn.c:73
JsonParseErrorType pg_parse_json_incremental(JsonLexContext *lex, JsonSemAction *sem, char *json, int len, bool is_last)
Definition: jsonapi.c:649
JsonSemAction nullSemAction
Definition: jsonapi.c:224
JsonParseErrorType pg_parse_json(JsonLexContext *lex, JsonSemAction *sem)
Definition: jsonapi.c:521
JsonLexContext * makeJsonLexContextCstringLen(JsonLexContext *lex, char *json, int len, int encoding, bool need_escapes)
Definition: jsonapi.c:326
void freeJsonLexContext(JsonLexContext *lex)
Definition: jsonapi.c:482
JsonLexContext * makeJsonLexContextIncremental(JsonLexContext *lex, int encoding, bool need_escapes)
Definition: jsonapi.c:366
JsonParseErrorType
Definition: jsonapi.h:37
@ JSON_SUCCESS
Definition: jsonapi.h:38
exit(1)
void pg_logging_init(const char *argv0)
Definition: logging.c:83
#define pg_fatal(...)
@ PG_UTF8
Definition: pg_wchar.h:232
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
Definition: stringinfo.c:233
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
#define BUFSIZE

References appendBinaryStringInfo(), BUFSIZE, StringInfoData::data, exit(), freeJsonLexContext(), i, initStringInfo(), JSON_SUCCESS, StringInfoData::len, makeJsonLexContextCstringLen(), makeJsonLexContextIncremental(), nullSemAction, pg_fatal, pg_logging_init(), pg_parse_json(), pg_parse_json_incremental(), and PG_UTF8.