Commit 70ccd807c45f477d6caf73b9390ba3acda53d1db

Authored by Jay Berkenbilt
1 parent 341cd7b5

Add json to performance tests

Showing 2 changed files with 61 additions and 18 deletions
@@ -84,9 +84,6 @@ General things to remember: @@ -84,9 +84,6 @@ General things to remember:
84 non-compatible json 2 changes. Scrutinize all the output to decide 84 non-compatible json 2 changes. Scrutinize all the output to decide
85 what should change. 85 what should change.
86 86
87 -* When we get to full serialization, add json serialization  
88 - performance test.  
89 -  
90 * Document that keys other than "qpdf-v2" are ignored so people can 87 * Document that keys other than "qpdf-v2" are ignored so people can
91 stash their own stuff. 88 stash their own stuff.
92 89
performance_check
@@ -18,6 +18,8 @@ my @tests = ( @@ -18,6 +18,8 @@ my @tests = (
18 ['shared resource check', ['--split-pages', '--remove-unreferenced-resources=auto']], 18 ['shared resource check', ['--split-pages', '--remove-unreferenced-resources=auto']],
19 ['linearize', ['--linearize']], 19 ['linearize', ['--linearize']],
20 ['encrypt', ['--encrypt', 'u', 'o', '256', '--']], 20 ['encrypt', ['--encrypt', 'u', 'o', '256', '--']],
  21 + ['json-output', ['--json-output']],
  22 + ['json-input', ['--json-input']],
21 ); 23 );
22 24
23 # If arg is not found in help output, look here. If not here, skip test. 25 # If arg is not found in help output, look here. If not here, skip test.
@@ -34,12 +36,14 @@ my $test_dir = undef; @@ -34,12 +36,14 @@ my $test_dir = undef;
34 my $test_file = undef; 36 my $test_file = undef;
35 my $workdir = undef; 37 my $workdir = undef;
36 my $maxtime = undef; 38 my $maxtime = undef;
  39 +my $iterations = undef;
37 40
38 my $default_executable = 'build/qpdf/qpdf'; 41 my $default_executable = 'build/qpdf/qpdf';
39 my $default_test_dir = '../performance-test-files'; 42 my $default_test_dir = '../performance-test-files';
40 my $default_test_file = undef; 43 my $default_test_file = undef;
41 my $default_workdir = 'build/perf'; 44 my $default_workdir = 'build/perf';
42 my $default_maxtime = 20; 45 my $default_maxtime = 20;
  46 +my $default_iterations = 20;
43 47
44 sub usage 48 sub usage
45 { 49 {
@@ -50,6 +54,7 @@ Usage: $whoami [ args ] @@ -50,6 +54,7 @@ Usage: $whoami [ args ]
50 --executable qpdf use the specified qpdf (default: $default_executable) 54 --executable qpdf use the specified qpdf (default: $default_executable)
51 --workdir where to write output pdfs (default: $default_workdir) 55 --workdir where to write output pdfs (default: $default_workdir)
52 --maxtime maximum time for a test; 0 means unlimited (default: $default_maxtime) 56 --maxtime maximum time for a test; 0 means unlimited (default: $default_maxtime)
  57 + --iterations number of iterations (default: $default_iterations)
53 "; 58 ";
54 } 59 }
55 60
@@ -83,6 +88,11 @@ while (@ARGV) @@ -83,6 +88,11 @@ while (@ARGV)
83 usage() unless @ARGV; 88 usage() unless @ARGV;
84 $maxtime = shift(@ARGV); 89 $maxtime = shift(@ARGV);
85 } 90 }
  91 + elsif ('--iterations' eq $arg)
  92 + {
  93 + usage() unless @ARGV;
  94 + $iterations = shift(@ARGV);
  95 + }
86 else 96 else
87 { 97 {
88 usage(); 98 usage();
@@ -105,21 +115,40 @@ if (! defined $maxtime) @@ -105,21 +115,40 @@ if (! defined $maxtime)
105 { 115 {
106 $maxtime = $default_maxtime; 116 $maxtime = $default_maxtime;
107 } 117 }
108 -  
109 -my @test_files = ();  
110 -if (defined $test_file) 118 +if (! defined $iterations)
111 { 119 {
112 - push(@test_files, $test_file); 120 + $iterations = $default_iterations;
113 } 121 }
114 -else  
115 -{  
116 - opendir(D, $test_dir) or  
117 - die "$whoami: can't open directory $test_dir: $!\n";  
118 - my @entries = readdir(D);  
119 - closedir(D);  
120 - for (sort @entries) 122 +
  123 +my @test_files = ();
  124 +my @json_test_files = ();
  125 +{ # private scope
  126 + my @tmp = ();
  127 + if (defined $test_file)
  128 + {
  129 + push(@tmp, $test_file);
  130 + }
  131 + else
  132 + {
  133 + opendir(D, $test_dir) or
  134 + die "$whoami: can't open directory $test_dir: $!\n";
  135 + my @entries = readdir(D);
  136 + closedir(D);
  137 + for (sort @entries)
  138 + {
  139 + push(@tmp, "$test_dir/$_") unless (('.' eq $_) || ('..' eq $_));
  140 + }
  141 + }
  142 + foreach my $i (@tmp)
121 { 143 {
122 - push(@test_files, "$test_dir/$_") unless (('.' eq $_) || ('..' eq $_)); 144 + if ($i =~ m/.json$/)
  145 + {
  146 + push(@json_test_files, $i);
  147 + }
  148 + else
  149 + {
  150 + push(@test_files, $i);
  151 + }
123 } 152 }
124 } 153 }
125 154
@@ -173,7 +202,16 @@ sub run_tests @@ -173,7 +202,16 @@ sub run_tests
173 print " skipping (unknown arguments)\n"; 202 print " skipping (unknown arguments)\n";
174 next; 203 next;
175 } 204 }
176 - foreach my $file (@test_files) 205 + my $test_files = \@test_files;
  206 + foreach my $arg (@$args)
  207 + {
  208 + if ($arg eq '--json-input')
  209 + {
  210 + $test_files = \@json_test_files;
  211 + last;
  212 + }
  213 + }
  214 + foreach my $file (@$test_files)
177 { 215 {
178 my $time = run_test($file, $args); 216 my $time = run_test($file, $args);
179 if (defined $time) 217 if (defined $time)
@@ -192,8 +230,16 @@ sub run_test @@ -192,8 +230,16 @@ sub run_test
192 { 230 {
193 my ($file, $args) = @_; 231 my ($file, $args) = @_;
194 232
195 - my $iterations = 20;  
196 - my @cmd = ($executable, @$args, $file, "$workdir/out.pdf"); 233 + my $outfile = "out.pdf";
  234 + foreach my $arg (@$args)
  235 + {
  236 + if ($arg eq '--json-output')
  237 + {
  238 + $outfile = "out.json";
  239 + last;
  240 + }
  241 + }
  242 + my @cmd = ($executable, @$args, $file, "$workdir/$outfile");
197 # Run once and discard to update caches 243 # Run once and discard to update caches
198 system("sync"); 244 system("sync");
199 system(@cmd); 245 system(@cmd);