Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Fastest byteswap (little endian to big endian (eg. 34127856 -> 12345678)

by Eily (Monsignor)
on Apr 14, 2015 at 07:54 UTC ( [id://1123369]=note: print w/replies, xml ) Need Help??


in reply to Fastest byteswap (little endian to big endian (eg. 34127856 -> 12345678)

Before v5.20 the copy on write feature of string was not activated by default. This means that you may win a little time by avoiding to copy the strings in multiple scalars: print $output pack("v*", unpack("n*", scalar <$fh>));

  • Comment on Re: Fastest byteswap (little endian to big endian (eg. 34127856 -> 12345678)
  • Download Code

Replies are listed 'Best First'.
Re^2: Fastest byteswap (little endian to big endian (eg. 34127856 -> 12345678)
by ikegami (Patriarch) on Apr 14, 2015 at 12:48 UTC
    What copying? No string is copied in that code. COW would not help.

      There is in the second method posted by james28909:

      my $data = do { local $/ = undef; open (my $fh, "<", $input_file) or die "could not open $input_file +: $!"; binmode($fh); <$fh>; }; my $reversed_data = pack( "v*", unpack( "n*", $data ) );
      But since it's not copied from one variable to another, it probably makes little difference indeed, I didn't think it through.

        That code does copy —note the assignment operator— but I think COW wouldn't help there either because I think the string would be stolen from the temp rather than copied.

Log In?
Username:
Password:

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

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

    No recent polls found