3 # Licensed to the Apache Software Foundation (ASF) under one or more
4 # contributor license agreements. See the NOTICE file distributed with
5 # this work for additional information regarding copyright ownership.
6 # The ASF licenses this file to You under the Apache License, Version 2.0
7 # (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
18 # ------------------------------------------
19 # compare.shingle.benchmark.jira.tables.pl
21 # Takes as cmdline parameters two JIRA-formatted benchmark results, as produced
22 # by shingle.bm2jira.pl (located in the same directory as this script), and
23 # outputs a third JIRA-formatted comparison table.
25 # The difference is calculated as a percentage:
27 # 100 * (unpatched-elapsed - patched-elapsed / patched-elapsed)
29 # where (un)patched-elapsed values have had the no-shingle-filter
30 # (StandardAnalyzer) elapsed time subtracted from them.
33 # Example shingle.bm2jira.pl output:
34 # ----------------------------------
36 # java version "1.5.0_15"
37 # Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_15-b04)
38 # Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_15-b04, mixed mode)
42 # WinVistaService Pack 2
43 # Service Pack 26060022202561
45 # ||Max Shingle Size||Unigrams?||Elapsed||
46 # |1 (Unigrams)|yes|2.19s|
55 my $usage = "Usage: $0 <unpatched-file> <patched-file>\n";
57 die $usage unless ($#ARGV == 1 && -f $ARGV[0] && -f $ARGV[1]);
61 open UNPATCHED, "<$ARGV[0]" || die "ERROR opening '$ARGV[0]': $!";
62 my $table_encountered = 0;
63 my $standard_analyzer_elapsed = 0;
64 my %unpatched_stats = ();
65 my %patched_stats = ();
67 unless ($table_encountered) {
68 if (/\Q||Max Shingle Size||Unigrams?||Elapsed||\E/) {
69 $table_encountered = 1;
73 } elsif (/\|([^|]+)\|([^|]+)\|([\d.]+)s\|/) {
74 my $max_shingle_size = $1;
75 my $output_unigrams = $2;
77 if ($max_shingle_size =~ /Unigrams/) {
78 $standard_analyzer_elapsed = $elapsed;
80 $unpatched_stats{$max_shingle_size}{$output_unigrams} = $elapsed;
86 open PATCHED, "<$ARGV[1]" || die "ERROR opening '$ARGV[1]': $!";
88 if (/\|([^|]+)\|([^|]+)\|([\d.]+)s\|/) {
89 my $max_shingle_size = $1;
90 my $output_unigrams = $2;
92 if ($max_shingle_size =~ /Unigrams/) {
93 $standard_analyzer_elapsed = $elapsed
94 if ($elapsed < $standard_analyzer_elapsed);
96 $patched_stats{$max_shingle_size}{$output_unigrams} = $elapsed;
102 print "||Max Shingle Size||Unigrams?||Unpatched||Patched||StandardAnalyzer||Improvement||\n";
103 for my $max_shingle_size (sort { $a <=> $b } keys %unpatched_stats) {
104 for my $output_unigrams (sort keys %{$unpatched_stats{$max_shingle_size}}) {
106 = ( $unpatched_stats{$max_shingle_size}{$output_unigrams}
107 - $patched_stats{$max_shingle_size}{$output_unigrams})
108 / ( $patched_stats{$max_shingle_size}{$output_unigrams}
109 - $standard_analyzer_elapsed);
110 $improvement = int($improvement * 1000 + .5) / 10; # Round and truncate
111 printf "|$max_shingle_size|$output_unigrams"
112 ."|$unpatched_stats{$max_shingle_size}{$output_unigrams}s"
113 ."|$patched_stats{$max_shingle_size}{$output_unigrams}s"
114 ."|${standard_analyzer_elapsed}s|%2.1f%%|\n", $improvement;