Debian Codegraph @

src/test/modules/test_json_parser/t/004_test_parser_perf.pl

raw
1
2 # Copyright (c) 2021-2025, PostgreSQL Global Development Group
3
4 # Test the JSON parser performance tester. Here we are just checking that
5 # the performance tester can run, both with the standard parser and the
6 # incremental parser. An actual performance test will run with thousands
7 # of iterations instead of just one.
8
9 use strict;
10 use warnings FATAL => 'all';
11
12 use PostgreSQL::Test::Utils;
13 use Test::More;
14 use FindBin;
15
16 use File::Temp qw(tempfile);
17
18 my $test_file = "$FindBin::RealBin/../tiny.json";
19
20 my $exe = "test_json_parser_perf";
21
22 my $contents = slurp_file($test_file);
23
24 my $dir = PostgreSQL::Test::Utils::tempdir;
25 my ($fh, $fname) = tempfile(DIR => $dir);
26
27 # repeat the input json file 50 times in an array
28
29 print $fh, '[', $contents, ",$contents" x 49, ']';
30
31 close($fh);
32
33 # but only do one iteration
34
35 my ($result) = run_log([ $exe, "1", $fname ]);
36
37 ok($result == 0, "perf test runs with recursive descent parser");
38
39 $result = run_log([ $exe, "-i", "1", $fname ]);
40
41 ok($result == 0, "perf test runs with table driven parser");
42
43 done_testing();