At a given point of some processing I have a list of polygons (an array of arrays of x y coordinates).
I want to generate a .png image of the filled polygons. There are a few modules I can use, GD, Imager, ImageMagick, PDL, maybe more.
I've tried GD vs Imager as in:

use GD; my $img = new GD::Image ($width, $height); my $black = $img->colorAllocate (0,0,0); my $white = $img->colorAllocate (255,255,255); map { my $polygon = GD::Polygon->new; map { $polygon->addPt (round ($_->[0] * $scale - $minx), round ($maxy - $_->[1] * $scale)); } @{$_}; $img->filledPolygon ($polygon,$white); } @polygons; print $img->png ();
use Imager; my $img = Imager->new (xsize=>$width, ysize=>$height, channels=>1, bits=>8); map { my @polygon = (); map { push (@polygon, [round ($_->[0] * $scale - $minx), round ($maxy - $_->[1] * $scale)]) } @{$_}; $img->polygon (points=>\@polygon, color=>'white'); } @polygons; $img->write (fd => fileno(STDOUT), type=>'png');

For a sample set size of 12690 polygons, generating a 7917x38558 image, the GD approach runs in about 7 seconds, the Imager approach runs in about 209 seconds, a very large difference.

Cursory inspection with top reveals very similar memory and CPU requirements

What am I overlooking, or is this the way it is?


In reply to Filling polygons: Imager vs GD by HASM

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.