#!/usr/bin/perl -w # benchmark_output_to_html.pl - Don Yang (uguu.org) # # Convert output of benchmark_crack.pl to HTML # # 2015-06-09 use strict; # Load input stats from CSV to memory sub LoadStats($$) { my ($accuracy, $latency) = @_; while( my $line = <> ) { next unless $line =~ /^(\d+),(\d+),([^,]+),([^,]+)/; $$accuracy{$1}{$2}{'value'} = sprintf '%0.2f', $3; $$accuracy{$1}{$2}{'color'} = $3 >= 0.5 ? $3 < 1.0 ? sprintf 'ffff%02x', int(255 * ($3 - 0.5) / 0.5) : '0fff0f' : sprintf 'ff%02x00', int(255 * $3 / 0.5); $$latency{$1}{$2}{'value'} = sprintf '%0.2f', $4; $$latency{$1}{$2}{'color'} = $4 >= 0.5 ? $4 < 1.0 ? sprintf 'ff%02x%02x', int(255 - 255 * ($4 - 0.5) / 0.5), int(255 - 255 * ($4 - 0.5) / 0.5) : 'ff0000' : 'ffffff'; } } # Write HTML page header to stdout sub WritePageHeader() { print < Benchmark stats EOT } # Write HTML page footer to stdout sub WritePageFooter() { print < EOT } # Write accuracy or latency table to stdout sub WriteTable($$) { my ($stats, $title) = @_; my @text_sizes = sort {$a <=> $b} keys %$stats; my %key_sizes; foreach my $f (keys %$stats) { $key_sizes{$_} = 1 foreach (keys %{$$stats{$f}}); } # Table header print "

$title

\n", "\n"; # Extra row at the top to make cell sizes uniform print "", ("" x (scalar @text_sizes)), "\n"; # Table rows my $first_row = 1; foreach my $k (sort {$a <=> $b} keys %key_sizes) { print ""; # Left axis if( $first_row ) { print ""; $first_row = 0; } print ""; # Data cells foreach my $t (@text_sizes) { print ""; } print "\n"; } # Bottom axis print ""; foreach my $t (@text_sizes) { print ""; } print "\n", "\n", "
    
", (" " x 4), "
key size
$k", $$stats{$t}{$k}{'value'}, "
"; if( $t >= 1000 ) { if( $t < 2000 ) { printf '%.1fk', $t / 1000; } else { print $t / 1000, "k"; } } else { print $t; } print "
text size
\n"; } my %accuracy = (); my %latency = (); LoadStats(\%accuracy, \%latency); WritePageHeader(); WriteTable(\%accuracy, "Accuracy"); WriteTable(\%latency, "Latency (seconds)"); WritePageFooter();