1/*-------------------------------------------------------------------------
3 * test_json_parser_perf.c
4 * Performance test program for both flavors of the JSON parser
6 * Copyright (c) 2024-2025, PostgreSQL Global Development Group
9 * src/test/modules/test_json_parser/test_json_parser_perf.c
11 * This program tests either the standard (recursive descent) JSON parser
12 * or the incremental (table driven) parser, but without breaking the input
13 * into chunks in the latter case. Thus it can be used to compare the pure
14 * parsing speed of the two parsers. If the "-i" option is used, then the
15 * table driven parser is used. Otherwise, the recursive descent parser is
18 * The remaining arguments are the number of parsing iterations to be done
19 * and the file containing the JSON input.
21 *-------------------------------------------------------------------------
35 main(
int argc,
char **argv)
50 if (strcmp(argv[1],
"-i") == 0)
56 sscanf(argv[1],
"%d", &iter);
58 if ((json_file = fopen(argv[2],
PG_BINARY_R)) == NULL)
59 pg_fatal(
"Could not open input file '%s': %m", argv[2]);
61 while ((n_read = fread(buff, 1, 6000, json_file)) > 0)
66 for (
int i = 0;
i < iter;
i++)
84 pg_fatal(
"unexpected result %d (expecting %d) on parse",
JsonParseErrorType pg_parse_json_incremental(JsonLexContext *lex, const JsonSemAction *sem, const char *json, size_t len, bool is_last)
JsonLexContext * makeJsonLexContextIncremental(JsonLexContext *lex, int encoding, bool need_escapes)
JsonParseErrorType pg_parse_json(JsonLexContext *lex, const JsonSemAction *sem)
JsonLexContext * makeJsonLexContextCstringLen(JsonLexContext *lex, const char *json, size_t len, int encoding, bool need_escapes)
const JsonSemAction nullSemAction
void freeJsonLexContext(JsonLexContext *lex)
void pg_logging_init(const char *argv0)
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
void initStringInfo(StringInfo str)
int main(int argc, char **argv)