add new comparison method rgb_difference that resembles arithmetical difference per...
[imager.git] / bench / quantbench.perl
CommitLineData
02d1d628
AMH
1#!perl -w
2use strict;
3use Data::Dumper;
4
5print <<EOS;
6This program benchmarks various RGB to palette index code segments (quant.c).
7
8The idea is to run it on various processors to see which is fastest on
9average.
10
11It takes about 50 minutes on my 700MHz PIII laptop.
12
13If you want to see what the output images look like, cd to .. and run:
14
15 perl -Mblib bench/quantone.perl foo
16
17which gives the output files a prefix of 'foo'.
18
19EOS
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";
25chdir ".." 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
32my %qopts = qw(hashbox IM_CFHASHBOX
33 rand2dist IM_CFRAND2DIST);
34
35
36# $bench{$opt}{$image}{$tran}{$pal} = time
37my %bench;
38$|++;
39unlink "bench/quantbench.txt";
40for 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
75system "uname -srmp >bench/quantbench.txt"; # is -srmp portable?
76open BENCH, ">> bench/quantbench.txt"
77 or die "Cannot open bench/quantbench.txt: $!";
78print BENCH Dumper(\%bench);
79close BENCH or die "Cannot close benchmark file: $!";
80print "Please email bench/quantbench.txt to tony\@develop-help.com\n";
81
82__END__
83
84=head1 NAME
85
86quantbench.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
95Builds Imager with various quantization code options, and then times
96the results of running with those options, with various palettes and
97options.
98
99The aim is to run this with several options on several platforms, and
100see which produces the fastest results overall.
101
102Requires that PNG and GIF (or ungif) support is present.
103
104=cut
105