Notice a difference? As the number of records increases, the first method will get slower. Why? Because you weren't smart enough to sort only the data you need. The two produce identical lists (unless you have severe magic going on, in which case, I don't wanna hear about it), but the second will produce it in better time, since you're only sorting the matches, not all the records.@small = grep { $_->size < 100 } sort $query->all_records; # vs. @small = sort grep { $_->size < 100 } $query->all_records;
($short) = $desc =~ /^(.{0,100})/; # breaks on embedded newlines, and is better as $short = substr($desc, 0, 100);
$name = substr($rec, 0, 20); $age = substr($rec, 20, 5); $job = substr($rec, 25, 25); # repeated calls to substr() better as unpack() ($name,$age,$job) = unpack 'A20 A5 A25', $rec;
if ($str =~ /jeff/) { ... } # why not if (index($str,'jeff') > -1) { ... } # or if you know that if it's there, it's toward the end: if (rindex($str,'jeff') > -1) { ... }
# (on average) s/[abc]*//g; # is FAR slower than s/[abc]//g; # is slower than s/[abc]+//g; # which is slower than tr/abc//d;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re (tilly) 1: Code Smarter
by tilly (Archbishop) on Nov 19, 2000 at 03:57 UTC | |
Re: Code Smarter
by metaperl (Curate) on Nov 20, 2000 at 04:34 UTC | |
by mischief (Hermit) on Dec 28, 2000 at 14:16 UTC | |
Re: Code Smarter
by salvadors (Pilgrim) on Dec 31, 2000 at 22:22 UTC | |
by I0 (Priest) on Dec 31, 2000 at 22:41 UTC | |
by ichimunki (Priest) on Jan 01, 2001 at 00:17 UTC | |
by I0 (Priest) on Jan 01, 2001 at 02:00 UTC | |
Re: Code Smarter
by tphyahoo (Vicar) on Nov 08, 2005 at 09:41 UTC |