]> git.imager.perl.org - imager.git/blob - bench/quantbench.perl
support libbase as an arrayref for fake probing
[imager.git] / bench / quantbench.perl
1 #!perl -w
2 use strict;
3 use Data::Dumper;
4
5 print <<EOS;
6 This program benchmarks various RGB to palette index code segments (quant.c).
7
8 The idea is to run it on various processors to see which is fastest on
9 average.
10
11 It takes about 50 minutes on my 700MHz PIII laptop.
12
13 If you want to see what the output images look like, cd to .. and run:
14
15   perl -Mblib bench/quantone.perl foo
16
17 which gives the output files a prefix of 'foo'.
18
19 EOS
20
21 -e 'hsvgrad.png' && -e 'rgbtile.png'
22   or die "Run makegrad.perl first";
23 -e 'kscdisplay.png' 
24   or die "Missing file. Download http://www.develop-help.com/imager/kscdisplay.png";
25 chdir ".." or die "Can't chdir to parent: $!";
26
27 #my %qopts = qw(linsearch IM_CFLINSEARCH
28 #               hashbox   IM_CFHASHBOX
29 #               sortchan  IM_CFSORTCHAN
30 #               rand2dist IM_CFRAND2DIST);
31
32 my %qopts = qw(hashbox   IM_CFHASHBOX
33                rand2dist IM_CFRAND2DIST);
34
35
36 # $bench{$opt}{$image}{$tran}{$pal} = time
37 my %bench;
38 $|++;
39 unlink "bench/quantbench.txt";
40 for my $opt (keys %qopts) {
41   open LOG, ">> bench/quantbench.log" or die "Cannot open log: $!";
42   print LOG "*** $opt ***\n";
43   close LOG;
44   $ENV{IM_CFLAGS} = "-DIM_CF_COPTS -D$qopts{$opt}";
45   print "*** $opt configuring";
46   system "perl Makefile.PL >>bench/quantbench.log 2>&1"
47     and die "Failed to configure Imager";
48   print " building";
49   system "make >>bench/quantbench.log 2>&1"
50     and die "Failed to build Imager";
51   print " benchmarking";
52   my @out = `perl -Mblib bench/quantone.perl`;
53   $? and die "Failed to run benchmark: $?";
54   chomp @out;
55   print "parsing\n";
56   my ($image, $tran);
57   foreach (@out) {
58     if (/^\*\*\s+(\S+)\s+(\S+)/) {
59       $image = $1;
60       $tran = $2;
61     }
62     elsif (/^\s*(\w+).*\@\s*([\d.]+)/ or /^\s*(\w+?):.+?([\d.]+?) CPU\)/) {
63                         print "$1: $2\n";
64       $bench{$opt}{$image}{$tran}{$1} = $2;
65     }
66     elsif (/^Benchmark:/) {
67       # ignored
68     }
69     else {
70       die "Unknown benchmark output: $_\n";
71     }
72   }
73 }
74
75 system "uname -srmp >bench/quantbench.txt"; # is -srmp portable?
76 open BENCH, ">> bench/quantbench.txt" 
77   or die "Cannot open bench/quantbench.txt: $!";
78 print BENCH Dumper(\%bench);
79 close BENCH or die "Cannot close benchmark file: $!";
80 print "Please email bench/quantbench.txt to tony\@develop-help.com\n";
81
82 __END__
83
84 =head1 NAME
85
86 quantbench.pl - Benchmarks Imager's image quantization code.
87
88 =head1 SYNOPSIS
89
90   perl makegrad.pl
91   perl quantbench.pl
92
93 =head1 DESCRIPTION
94
95 Builds Imager with various quantization code options, and then times
96 the results of running with those options, with various palettes and
97 options.
98
99 The aim is to run this with several options on several platforms, and
100 see which produces the fastest results overall.
101
102 Requires that PNG and GIF (or ungif) support is present.
103
104 =cut
105