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); };
In reply to Unexpected: unpack slower than several substr's. Why? by BazB
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |