Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Fixed-Length Fields Question

by ase (Monk)
on Jul 24, 2000 at 15:04 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://24048]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-25 17:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found