On Tue, 3 Jul 2001, Maxim Berlin wrote:

> Tuesday, July 03, 2001, Brett W. McCoy <[EMAIL PROTECTED]> wrote:
>
> >> > > > Unpack works well with fixed format data like this.
> >> > >
> >> > > Why would you use unpack when this can be easily split apart with a regex?
> >> > > I'd think unpack would be overkill!
> >>
> >> why is it overkill any more that a regex?
>
> BWM> Are you saying we should be using unpack rather than regular expressions?
>
> mak@freebus/usr/home/mak>perl t.pl
> Benchmark: timing 100000 iterations of regexp, unpack...
>     regexp: 15 wallclock secs (14.61 usr +  0.00 sys = 14.61 CPU)
>     unpack: 12 wallclock secs (11.17 usr +  0.00 sys = 11.17 CPU)

I did some similar profiling using the Unix time command, and found it was
about even, after about 10 runs each, reading in a file and processing
10,000 dates -- they each averaged a little under 6 seconds each.  Both
actually went to under 5 seconds in a couple of instances, with the unpack
tending to be slightly faster (but not always -- sometimes the regex
version ran faster).

The slight performance gain you might get with unpack doesn't compare to
the flexibility of a regular expression.  If the date style changes to,
say, 02July01 (instead of 2July2001), the regular expression will still
work and the code does not need to be changed.  The code would need to be
modified for the unpack version to continue to work (since it was checking
for the length of the string).  I would prefer the general solution to the
more specific unless the performance gain of the latter is significant.
In this case, it isn't.

-- Brett
                                    http://www.chapelperilous.net/btfwk/
------------------------------------------------------------------------
An investment in knowledge always pays the best interest.
                -- Benjamin Franklin

Reply via email to