You know what, tilly is right. I always get into trouble every time I assume that unpack will do its job faster than a regexp.

Here's a test snippet proving tilly's point and disproving my earlier assertion:

use strict; use warnings; use Benchmark; my @stuff; while ( my $line = <DATA> ) { chomp $line; push @stuff, $line; } sub do_split { my @parsed; push( @parsed, split( /\|/, $_ ) ) for @stuff; return scalar @parsed; } sub do_unpack { my @parsed; push( @parsed, unpack( 'a5xa5xa5xa5xa5xa5xa5xa5xa5xa5x', $_ ) ) for @stuff; return scalar @parsed; } my $count = 100000; timethese ( $count, { SPLIT => \&do_split, UNPACK => \&do_unpack } ); __DATA__ AAAAA|BBBBB|CCCCC|DDDDD|EEEEE|11111|22222|33333|44444|55555| FFFFF|GGGGG|HHHHH|IIIII|JJJJJ|11111|22222|33333|44444|55555| KKKKK|LLLLL|MMMMM|NNNNN|OOOOO|11111|22222|33333|44444|55555| PPPPP|QQQQQ|RRRRR|SSSSS|TTTTT|11111|22222|33333|44444|55555| UUUUU|VVVVV|WWWWW|XXXXX|YYYYY|11111|22222|33333|44444|55555| ZZZZZ|aaaaa|bbbbb|ccccc|ddddd|11111|22222|33333|44444|55555| AAAAA|BBBBB|CCCCC|DDDDD|EEEEE|11111|22222|33333|44444|55555| FFFFF|GGGGG|HHHHH|IIIII|JJJJJ|11111|22222|33333|44444|55555| KKKKK|LLLLL|MMMMM|NNNNN|OOOOO|11111|22222|33333|44444|55555| PPPPP|QQQQQ|RRRRR|SSSSS|TTTTT|11111|22222|33333|44444|55555| UUUUU|VVVVV|WWWWW|XXXXX|YYYYY|11111|22222|33333|44444|55555| ZZZZZ|aaaaa|bbbbb|ccccc|ddddd|11111|22222|33333|44444|55555|

The output:

Benchmark: timing 100000 iterations of SPLIT, UNPACK... SPLIT: 25 wallclock secs (23.92 usr + 0.01 sys = 23.93 CPU) @ 4178.16/s (n=100000) UNPACK: 26 wallclock secs (25.62 usr + 0.01 sys = 25.63 CPU) @ 3902.13/s (n=100000)


Dave


In reply to Re: Re: Re: Re: Re: Need to process a tab delimted file *FAST* by davido
in thread Need to process a tab delimted file *FAST* by devnul

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.