Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re^3: Skip a row of csv file.

by aaron_baugher (Curate)
on May 04, 2012 at 23:35 UTC ( #969003=note: print w/ replies, xml ) Need Help??

in reply to Re^2: Skip a row of csv file.
in thread Skip a row of csv file.

You make a good point, but I found myself wondering how the combination of substr, length, and eq would compare to a single anchored regex, so I did a benchmark. I'm convinced!

bannor:~/work/perl/monks$ cat #!/usr/bin/env perl use Modern::Perl; use Benchmark qw(:all); my $str = 'A.SERIAL_NUMBER||abcdefghijklmnopqrstuvwxyz'; my $ss = 'A.SERIAL_NUMBER||'; my $yay; cmpthese( 10_000_000, { 'substr' => sub { if(substr($str,0,length($ss)) eq $ss ){ $yay = 1; } }, 'regex' => sub { if( $str =~ /^\Q$ss\E/ ){ $yay = 1; } }, }); bannor:~/work/perl/monks$ perl Rate regex substr regex 1312336/s -- -65% substr 3802281/s 190% --

Aaron B.
My Woefully Neglected Blog, where I occasionally mention Perl.

Comment on Re^3: Skip a row of csv file.
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://969003]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2015-11-27 11:12 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (724 votes), past polls