SPUG: print statement taking ridiculously long
Thomas Sibley
tsibley at cpan.org
Tue Jul 23 10:34:49 PDT 2013
On 07/23/2013 10:19 AM, Fred Morris wrote:
> We've got a script. It produces a huge string after much thrashing:
>
> $big_string = "60 Megs or so";
>
> Then it tries to write it to a file:
>
> open OUT, ">$file";
> print OUT $big_string;
> close OUT;
>
> Well that print statement takes over half an hour with one core running at
> 100% CPU! For that matter we've discovered that taking the length of
> $big_string takes an inordinate amount of time as well. The job doesn't
> appear to be swapping.
>
> This is happening on the Debian build of perl 5.14. It runs (the whole script)
> in 5 minutes or so on other (older) versions of perl on far more modest
> hardware.
>
> Thoughts?
I'd take a look at your disk IO. (Are you writing to a network FS? Is
your disk dying?)
tom at whaam ~ $ cat long-string
use strict;
use warnings;
my $big_string = "a" x (60 * 1024**2);
open my $out, ">", "/tmp/big" or die $!;
print { $out } $big_string;
close $out or die $!;
tom at whaam ~ $ perlbrew exec -- time --format "took %es" perl long-string
perl-5.10.1
==========
took 0.20s
perl-5.12.5
==========
took 0.17s
perl-5.14.1
==========
took 0.17s
perl-5.16.3
==========
took 0.16s
perl-5.18
==========
took 0.17s
perl-5.8.3
==========
took 0.19s
perl-5.8.8
==========
took 0.19s
More information about the spug-list
mailing list