Debian Codegraph @

tools/bench.pl

raw symbols SCIP
1 #!/usr/bin/perl
2
3 use strict;
4
5 use Benchmark::Dumb qw(:all);
6 use Image::Scale;
7 use GD;
8
9 GD::Image->trueColor(1);
10
11 my $path = shift || die "Path required\n";
12 my $width = shift || die "Width required\n";
13 my $saves = {};
14
15 warn "Benchmarking $path resized to $width...\n";
16
17 my $jpg = $path =~ /jpe?g/i ? 1 : 0;
18
19 my $tests = {
20 resize_gd => sub {
21 my $img = Image::Scale->new($path);
22 $img->resize_gd( { width => $width } );
23 my $out = $jpg ? $img->as_jpeg() : $img->as_png();
24 if ( !$saves->{resize_gd}++ ) {
25 open my $fh, '>', 'resize_gd.' . ($jpg ? 'jpg' : 'png');
26 print $fh $out;
27 close $fh;
28 }
29 },
30 resize_gd_fixed => sub {
31 my $img = Image::Scale->new($path);
32 $img->resize_gd_fixed_point( { width => $width } );
33 my $out = $jpg ? $img->as_jpeg() : $img->as_png();
34 if ( !$saves->{resize_gd_fixed}++ ) {
35 open my $fh, '>', 'resize_gd_fixed_point.' . ($jpg ? 'jpg' : 'png');
36 print $fh $out;
37 close $fh;
38 }
39 },
40 resize_gm => sub {
41 my $img = Image::Scale->new($path);
42 $img->resize_gm( { width => $width, filter => 'Triangle' } );
43 my $out = $jpg ? $img->as_jpeg() : $img->as_png();
44 if (!$saves->{"resize_gm"}++) {
45 open my $fh, '>', "resize_gm." . ($jpg ? 'jpg' : 'png');
46 print $fh $out;
47 close $fh;
48 }
49 },
50 resize_gm_fixed => sub {
51 my $img = Image::Scale->new($path);
52 $img->resize_gm_fixed_point( { width => $width } );
53 my $out = $jpg ? $img->as_jpeg() : $img->as_png();
54
55 if ( !$saves->{resize_gm_fixed}++ ) {
56 open my $fh, '>', 'resize_gm_fixed_point.' . ($jpg ? 'jpg' : 'png');
57 print $fh $out;
58 close $fh;
59 }
60 },
61 };
62
63 if ( ($jpg && GD::Image->can('newFromJpeg')) || (!$jpg && GD::Image->can('newFromPng')) ) {
64 $tests->{gd_resample} = sub {
65 my $src = $jpg ? GD::Image->newFromJpeg($path) : GD::Image->newFromPng($path);
66 my $dst = GD::Image->new($width, $width);
67 $dst->copyResampled(
68 $src,
69 0, 0,
70 0, 0,
71 $width, $width,
72 $src->width, $src->height
73 );
74
75 my $out = $jpg ? $dst->jpeg(90) : $dst->png;
76
77 if (!$saves->{gd_resample}++) {
78 open my $fh, '>', 'gd.' . ($jpg ? 'jpg' : 'png');
79 print $fh $out;
80 close $fh;
81 }
82 };
83 }
84
85 cmpthese( 0.005, $tests );