2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 02:49:00 +00:00

Performance check: add test for extraction of single page

It is common to just read a few objects. Checking extraction of the
first page exercises this to make sure we don't accidentally introduce
a change that makes that case worse, such as adding an unnecessary
traversal of the file, prematurely resolving objects we don't need,
etc.
This commit is contained in:
Jay Berkenbilt 2022-11-25 13:16:00 -05:00
parent 562ff1b608
commit 3630a8c597

View File

@ -12,6 +12,8 @@ my $whoami = basename($0);
$| = 1; $| = 1;
# [ name, [ args ] ] # [ name, [ args ] ]
# If <IN> appears, it is replaced with the input file name. Otherwise,
# the input file name is added to the end of the arguments.
my @tests = ( my @tests = (
['no arguments', []], ['no arguments', []],
['generate object streams', ['--object-streams=generate']], ['generate object streams', ['--object-streams=generate']],
@ -20,6 +22,7 @@ my @tests = (
['shared resource check', ['--split-pages', '--remove-unreferenced-resources=auto']], ['shared resource check', ['--split-pages', '--remove-unreferenced-resources=auto']],
['linearize', ['--linearize']], ['linearize', ['--linearize']],
['encrypt', ['--encrypt', 'u', 'o', '256', '--']], ['encrypt', ['--encrypt', 'u', 'o', '256', '--']],
['extract first page', ['--empty', '--pages', '<IN>', '1', '--']],
['json-output', ['--json-output']], ['json-output', ['--json-output']],
['json-input', ['--json-input']], ['json-input', ['--json-input']],
); );
@ -214,7 +217,7 @@ sub filter_args
{ {
my $to_check = $arg; my $to_check = $arg;
$to_check =~ s/=.*$//; $to_check =~ s/=.*$//;
if (index($help, $to_check) == -1) if (($to_check =~ m/^-/) && (index($help, $to_check) == -1))
{ {
my $new_arg = $arg_compat{$arg}; my $new_arg = $arg_compat{$arg};
if (! defined $new_arg) if (! defined $new_arg)
@ -287,15 +290,27 @@ sub run_test
my ($file, $args) = @_; my ($file, $args) = @_;
my $outfile = "out.pdf"; my $outfile = "out.pdf";
foreach my $arg (@$args) my $found_in = 0;
my @cmd = ($executable, @$report_mem);
for (@$args)
{ {
my $arg = $_;
if ($arg eq '--json-output') if ($arg eq '--json-output')
{ {
$outfile = "out.json"; $outfile = "out.json";
last;
} }
elsif ($arg eq '<IN>')
{
$found_in = 1;
$arg = $file;
} }
my @cmd = ($executable, @$args, @$report_mem, $file, "$workdir/$outfile"); push(@cmd, $arg);
}
if (! $found_in)
{
push(@cmd, $file);
}
push(@cmd, "$workdir/$outfile");
# Run once and discard to update caches # Run once and discard to update caches
system("sync"); system("sync");
run_cmd(@cmd); run_cmd(@cmd);