BazB has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to squeeze some more speed out of some code that I've got.
The code in question carries out 15 substr operations for each line of input.
I was expecting a single unpack to be faster, however this wasn't the case.
Could anyone explain what's going on?
Which modules could help trace this sort of issue? Things like Devel::DProf aren't quite the right tool.
Cheers.
BazB.
Benchmarks and code follow...
The code containing the pack/substr is generated using positions slurped from a data dictionary, then eval'ed producing the following:Benchmark: timing 100000 iterations of substr, unpack... Rate unpack substr unpack 40486/s -- -28% substr 55866/s 38% --
sub { my $line = shift; my @data; $data[0] = substr($line, 413, 30); $data[1] = substr($line, 373, 30); $data[2] = substr($line, 343, 30); # etc... $data[12] = substr($line, 454, 30); $data[13] = substr($line, 240, 3); $data[14] = substr($line, 236, 4); return @data; }; #------------------------------------- sub { my $line = shift; my @data = unpack('@413A30 @373A30 @343A30 # etc... @454A30 @240A3 @236A4', $line); };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unexpected: unpack slower than several substr's. Why?
by BrowserUk (Patriarch) on Jan 14, 2003 at 02:42 UTC | |
by MarkM (Curate) on Jan 14, 2003 at 02:53 UTC | |
by BrowserUk (Patriarch) on Jan 14, 2003 at 03:03 UTC | |
by steves (Curate) on Jan 14, 2003 at 03:16 UTC | |
by BazB (Priest) on Jan 14, 2003 at 20:55 UTC | |
|
Re: Unexpected: unpack slower than several substr's. Why?
by MarkM (Curate) on Jan 14, 2003 at 02:20 UTC | |
|
Re: Unexpected: unpack slower than several substr's. Why?
by theorbtwo (Prior) on Jan 14, 2003 at 02:17 UTC | |
|
Re: Unexpected: unpack slower than several substr's. Why?
by steves (Curate) on Jan 14, 2003 at 01:46 UTC |