Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-20 01:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found