There are many factors to consider when comparing the performance of your two models.
First, substr() and unpack() behave differently:
Secondly, Perl treats scalar assignments different from list assignments. In fact, the scalar assignment op-code is implemented much simpler. Benchmark the difference between "($a) = (1)" and "$a = 1" to see the effect that this has. Although 15+ scalar assignments may be more expensive than a list assignment that involves 15+ values, the overhead of a list assignment dampens the overhead of having many scalar assignments.
The only true way of comparing the two approaches, is the method that you have chosen -- benchmarking.
If you need to improve the performance of your substr() model, one (ugly) approach may be to use one large list assignment ("@data = (substr(), substr(), ...)") the same as you do for unpack(). Again, only benchmarking can tell... :-)
UPDATE: substr() only uses magic if called in lvalue context.
In reply to Re: Unexpected: unpack slower than several substr's. Why?
by MarkM
in thread Unexpected: unpack slower than several substr's. Why?
by BazB
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |