Commit 70ccd807c45f477d6caf73b9390ba3acda53d1db
1 parent
341cd7b5
Add json to performance tests
Showing
2 changed files
with
61 additions
and
18 deletions
TODO
| ... | ... | @@ -84,9 +84,6 @@ General things to remember: |
| 84 | 84 | non-compatible json 2 changes. Scrutinize all the output to decide |
| 85 | 85 | what should change. |
| 86 | 86 | |
| 87 | -* When we get to full serialization, add json serialization | |
| 88 | - performance test. | |
| 89 | - | |
| 90 | 87 | * Document that keys other than "qpdf-v2" are ignored so people can |
| 91 | 88 | stash their own stuff. |
| 92 | 89 | ... | ... |
performance_check
| ... | ... | @@ -18,6 +18,8 @@ my @tests = ( |
| 18 | 18 | ['shared resource check', ['--split-pages', '--remove-unreferenced-resources=auto']], |
| 19 | 19 | ['linearize', ['--linearize']], |
| 20 | 20 | ['encrypt', ['--encrypt', 'u', 'o', '256', '--']], |
| 21 | + ['json-output', ['--json-output']], | |
| 22 | + ['json-input', ['--json-input']], | |
| 21 | 23 | ); |
| 22 | 24 | |
| 23 | 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 | 36 | my $test_file = undef; |
| 35 | 37 | my $workdir = undef; |
| 36 | 38 | my $maxtime = undef; |
| 39 | +my $iterations = undef; | |
| 37 | 40 | |
| 38 | 41 | my $default_executable = 'build/qpdf/qpdf'; |
| 39 | 42 | my $default_test_dir = '../performance-test-files'; |
| 40 | 43 | my $default_test_file = undef; |
| 41 | 44 | my $default_workdir = 'build/perf'; |
| 42 | 45 | my $default_maxtime = 20; |
| 46 | +my $default_iterations = 20; | |
| 43 | 47 | |
| 44 | 48 | sub usage |
| 45 | 49 | { |
| ... | ... | @@ -50,6 +54,7 @@ Usage: $whoami [ args ] |
| 50 | 54 | --executable qpdf use the specified qpdf (default: $default_executable) |
| 51 | 55 | --workdir where to write output pdfs (default: $default_workdir) |
| 52 | 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 | 88 | usage() unless @ARGV; |
| 84 | 89 | $maxtime = shift(@ARGV); |
| 85 | 90 | } |
| 91 | + elsif ('--iterations' eq $arg) | |
| 92 | + { | |
| 93 | + usage() unless @ARGV; | |
| 94 | + $iterations = shift(@ARGV); | |
| 95 | + } | |
| 86 | 96 | else |
| 87 | 97 | { |
| 88 | 98 | usage(); |
| ... | ... | @@ -105,21 +115,40 @@ if (! defined $maxtime) |
| 105 | 115 | { |
| 106 | 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 | 202 | print " skipping (unknown arguments)\n"; |
| 174 | 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 | 216 | my $time = run_test($file, $args); |
| 179 | 217 | if (defined $time) |
| ... | ... | @@ -192,8 +230,16 @@ sub run_test |
| 192 | 230 | { |
| 193 | 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 | 243 | # Run once and discard to update caches |
| 198 | 244 | system("sync"); |
| 199 | 245 | system(@cmd); | ... | ... |