[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Sheflug] Perl tips
On Mon, Nov 25, 2002 at 04:19:34PM +0000, Alex Hudson wrote:
> On Mon, Nov 25, 2002 at 04:05:40PM +0000, Dave Mitchell wrote:
> > Except of course that the function will be called NlogN times, which
> > may then make it rather slow.
>
> O(NlogN) function versus a similar order data structure - I think I
> did point out that it would be exchanging speed for space :)
Pointless benchmark follows :-)
on my work desktop system (sparc/solaris),
using a hash took 6 secs and a 7.2M process size;
using a function took 34 secs and a 5M process.
But since my desktop system isn't even Linux, perhaps I better shut up for
the time being on this list :-)
Dave.
--
That he said that that that that is is is debatable, is debatable.
#!/usr/bin/perl -w
local $/;
@ARGV = ('/usr/dict/words');
@words = split /\n/, <>;
sub munge { $_[0] =~ /^(...)(.+)$/ ? "$2$1" : $_[0] }
sub s1 {
@words2 = sort { munge($a) cmp munge($b) } [at] words;
}
sub s2 {
$words{$_} = munge($_) for [at] words;
@words2 = sort { $words{$a} cmp $words{$b} } [at] words;
}
$t=time;
s1; # or s2
$t=time-$t;
print "took $t secs\n";
system("ps -lfyp $$");
___________________________________________________________________
Sheffield Linux User's Group -
http://www.sheflug.co.uk/mailfaq.html
GNU the choice of a complete generation.