#! perl -slw use strict; use threads; use Thread::Queue; use Time::HiRes qw[ time ]; use GD; sub rgb2n{ local $^W; unpack 'N', pack 'CCCC', 0, @_ } my $i = GD::Image->new( 1000, 1000, 1 ); my $start = time; for my $y ( 0 .. 999 ) { for my $x ( 0 .. 999 ) { $i->setPixel( $x, $y, rgb2n( map int( rand 256 ), 1.. 3 ) ); } } my $end = time; printf "Filling a 1000x1000 pixel image 1-pixel at a time took: %.9fs\n", $end - $start; #open O, '>:raw', 'junk.png'; print O $i->png; close O; system 1, 'junk.png'; my @cols; $start = time; for my $y ( 0 .. 999 ) { my @row; for my $x ( 0 .. 999 ) { push @row, [ $x, $y ]; } push @cols, \@row; } my $Q = new Thread::Queue; $Q->enqueue( \@cols ); async{ my $rCols = $Q->dequeue; }->join; $end = time; printf "Populating 1000x1000 AoAoAs and tranferring to another thread took: %.9fs\n", $end - $start;