Update - Perhaps I posted too soon. I've noticed that this problem doesn't happen with perl 5.8.3, but it does with 5.8.0 on one machine but not on another. Perhaps other monks can try it with different versions of perl for comparison?
Some minimal sample code:
use List::Util 'shuffle'; use Time::HiRes qw(gettimeofday tv_interval); my $N = 500_000; my $t1 = [gettimeofday]; my @a = (1 .. $N); prof("array created"); my @b = shuffle @a; prof("array shuffled"); my @c = sort {$a <=> $b} @b; prof("array sorted"); sub prof{ my $name = shift; my $t2 = [gettimeofday]; my $delta = tv_interval($t1, $t2); print "$delta\t$name\n"; $t1 = $t2; }
Which gives this output:
$ time ./t2.pl 0.268895 array created 0.359648 array shuffled 2.382604 array sorted real 0m22.609s user 0m21.820s sys 0m0.220s
Noticed that the real time is 22 s, which means that the proccess finished almost 20 s after it finished sorting (that's why I call this a "clean-up" delay for lack of a better name. I don't know how the internals work, but this problem doesn't happen when I don't sort. If I remove the sort line, I get:
0.488084 array created 0.739037 array shuffled real 0m1.547s
Even if I increase $N to 5_000_000, the cleanup time when not sorting is reasonably fast:
2.729688 array created 4.622434 array shuffled real 0m8.948s
Anyone has any idea about why this happens? I'm using perl 5.8.0 on linux.
In reply to Sort taking a long time to clean up by itub
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |