Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Fixed-Length Fields Question

by ase (Monk)
on Jul 24, 2000 at 15:04 UTC ( #24048=note: print w/replies, xml ) Need Help??


in reply to Fixed-Length Fields Question

I ran the following quick Benchmark code to test:
#!/usr/bin/perl -w use strict; use Benchmark; my $input = 'X' x 65; #test input my @result; timethese(-10, { 'Regex' => sub { @result = ($input =~ /(.{16})(.{20})(.{20})(.{1})(. +{8})/); # print join "\t", @result; }, 'Unpack' => sub { @result = unpack "A16A20A20AA8",$input; # print join "\t", @result; }, });
which yielded:
Benchmark: running Regex, Unpack, each for at least 10 CPU seconds... Regex: 9 wallclock secs (10.44 usr + 0.00 sys = 0.44 CPU) @ 198 +59.10/s (n=207329) Unpack: 11 wallclock secs (10.17 usr + 0.00 sys = 0.17 CPU) @ 333 +12.29/s (n=338786)

It would seem unpack is more efficient in this case.
-ase

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2020-06-01 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (12 votes). Check out past polls.

    Notices?