Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Null-stripping performance

by Thelonius (Priest)
on Feb 26, 2007 at 14:01 UTC ( [id://602123]=note: print w/replies, xml ) Need Help??


in reply to Null-stripping performance

I'd recommend:
$value = unpack "x$index Z4", $string;
or
$value = substr($string, $index, 4); $value =~ y/\0//d;

Replies are listed 'Best First'.
Re^2: Null-stripping performance
by Thelonius (Priest) on Feb 26, 2007 at 14:37 UTC
    On my PC, The "substr(), y" method takes about 0.6 microseconds, the "substr(), s" method takes about 1 microsecond, the "unpack x$index" method takes about 2 microseconds.

    The "unpack a$index" method takes about 41 microseconds (when averaged over a 262000 byte string), so it's the one to avoid. It has to allocate the large substring it skips over before it throws it away.

      Thanks a lot. I really appreciate your help! I can mention, as a parenthesis, that this code is going to run in sparc solaris-environment. When I tried the script at my PC perl took care of the null's by itself and just the substr worked fine. I guess I have to live with the time it takes to do it "substr(),y"-way. Thanks again

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2025-06-13 00:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.