디렉토리를 스캔하고 imgsize http://dktools.sourceforge.net/imgsize.html을 사용하여 작업하는 펄 스크립트가 png 파일의 너비 등을 가져옵니다. 누구든지이 프로세스의 속도를 높이는 데 도움이되는 조언이 있습니까 (현재 1000 개 파일 당 평균 5 분). 코드가 어떻게 최적화 될 수 있는지 궁금합니다. 감사.펄에서 foreach 루프를 가속화합니다.
use strict;
use warnings;
use File::Find;
my @files;
my $directory = '/Graphics/';
my $output_file = '/output_file';
my $max_height = 555;
my $count = 0;
open (OUTPUT, '>>', $output_file);
find(\&wanted, $directory);
foreach my $file (@files) {
if ($file =~ /\.png$/) {
my $height = `imgsize $file | cut -d\'\"\' -f4`;
if ($height > $max_height) {
print OUTPUT "$file\n";
}
$count++;
my $int_check = $count/1000;
if ($int_check !~ /\D/) {
print "processed: $count\n";
}
}
}
print "total: $count\n";
close (OUTPUT);
exit;
sub wanted {
push @files, $File::Find::name;
return;
}
솔루션 : 나는이 Image::Info
모듈을 사용 할 수 있었다고 밝혀졌습니다. 나는 매 5 분마다 1000 개의 img를 처리 할 때마다 12 초으로 갔다. 관심있는 사람이 있으면 관련 코드 스 니펫을 참조하십시오.
use Image::Info qw(image_info);
foreach my $file (@files) {
if ($file =~ /\.png$/) {
my $output = image_info($file);
my $height = ${$output}{height};
if ($height > $max_height) {
print OUTPUT "$file\n";
}
$count++;
my $int_check = $count/1000;
if ($int_check !~ /\D/) {
print "processed: $count\n";
}
}
}
스크립트를 프로파일 링 했습니까? [DeveL :: NYTProf] (http://p3rl.org/Devel::NYTProf)는 프로파일 링에 유용합니다. – choroba
병목 현상이'imgsize' 어플리케이션이라고 가정합니다. 병렬로 여러 인스턴스를 실행할 수도 있습니다. 예를 들어 [Parallel :: ForkManager] (http : // p3rl/Parallel :: ForkManager)를 참조하십시오. – ElPaco
고맙습니다. @choroba 내가 살펴볼 것입니다. –