Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Nice! Benchmark of various solutions (I hope I did not spoil it again):
#!/usr/bin/perl use warnings; use strict; use Test::More tests => 5; use Benchmark qw(cmpthese); my $bits = join q(), map chr rand 256, 1 .. 1e7; sub single { $_[0] =~ s/(.)/~$1/ges; } sub long { $_[0] =~ s/(.{1,10000})/~$1/ges; } sub classic { $_[0] = ~$_[0]; } sub str { my $blocksize = 10000; my $lb = length $_[0]; my $offset = 0; while( $offset < $lb ) { substr $_[0], $offset, $blocksize, ~substr( $_[0], $offset, $blocksize ); $offset += $blocksize; } } BEGIN { my $chars = join q(), map sprintf('\x%02x', $_), 0 .. 255; my $rev = join q(), map sprintf('\x%02x', $_), reverse 0 .. 255; eval "sub translate { \$_[0] =~ tr/$chars/$rev/ } ; 1 " or die $@; } my $copy = $bits; classic($copy) for 1 .. 2; is($bits, $copy, 'double negation'); single($copy); classic($bits); is($bits, $copy, 'single - classic'); classic($bits); long($copy); is($bits, $copy, 'classic - long'); classic($bits); translate($copy); is($bits, $copy, 'classic - translate'); classic($bits); str($copy); is($bits, $copy, 'classic - str'); cmpthese(-10, { classic => sub { classic($bits) }, single => sub { single($bits) }, long => sub { long($bits) }, translate => sub { translate($bits) }, str => sub { str($bits) }, } );

Output on my machine:

1..5 ok 1 - double negation ok 2 - single - classic ok 3 - classic - long ok 4 - classic - translate ok 5 - classic - str Rate single translate long classic str single 0.328/s -- -100% -100% -100% -100% translate 161/s 48834% -- -26% -39% -59% long 217/s 66040% 35% -- -18% -45% classic 263/s 80093% 64% 21% -- -33% str 394/s 119839% 145% 81% 50% --
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

In reply to Re^2: In-place bitwise NOT? by choroba
in thread In-place bitwise NOT? by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others having an uproarious good time at the Monastery: (7)
    As of 2014-11-27 02:11 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My preferred Perl binaries come from:














      Results (178 votes), past polls