Hi all,
I try to create a queue for multithreaded processing of a huge image file.
Here is what i figured out:
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dump;
use Time::HiRes qw(time);
# use feature qw(say);
my $start = time;
my @queue;
my @line;
# ratio 1.25 - i guess 160 pixel
# my $width = 20;
# my $height = 8;
# my $qsize = 4;
# same ratio - i guess 20 MP
my $width = 1280 * 4;
my $height = 1024 * 4;
my $qsize = 32;
for my $x ( 0 .. $width - 1 ) {
for my $y ( 0 .. $height - 1 ) {
my $coords = [ $x, $y ];
push @line, $coords;
if ( scalar @line == $width ) {
push @queue, [@line];
@line = ();
# audacious actions start here
if ( scalar @queue == $qsize ) {
# dd \@queue;
@queue = ();
}
}
}
}
printf "Took %.3f seconds\n", time - $start;
__END__
karls-mac-mini:monks karl$ ./queue.pl
Took 13.531 seconds
It looks like it works as designed.
But i can't suppress the vague feeling that this solution is ungeschickt.
How can i improve this code?
Update: Thank you very much to all that contributed to this interesting thread. I have little time this week, but when i have studied the numerous examples given, i'll reply more detailed respectively ask more questions :-)
Thank you very much for any hint and best regards,
Karl
«The Crux of the Biscuit is the Apostrophe»
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|