Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: In-place bitwise NOT?

by hdb (Monsignor)
on Jul 26, 2013 at 17:44 UTC ( [id://1046575]=note: print w/replies, xml ) Need Help??


in reply to In-place bitwise NOT?

Create a bitstring class that supports lazy evaluation.

UPDATE: Loop using substr

my $blocksize = 1000000; my $lb = length $bin; my $offset = 0; while( $offset < $lb ) { substr $bin, $offset, $blocksize, ~substr( $bin, $offset, $blocksize + ); $offset += $blocksize; }

Too slow as well?

Replies are listed 'Best First'.
Re^2: In-place bitwise NOT?
by choroba (Cardinal) on Jul 26, 2013 at 18:17 UTC
    Nice! Benchmark of various solutions (I hope I did not spoil it again):

    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% --
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Here's my version of that. The first run is on a 1MB string will all tests enabled.

      The second run is on a 1GB string with the classic and s/// solutions disable because life's too short :)

      C:\test>1046579 -N=2**20 1048576 Rate single long classic str translate single 1.72/s -- -99% -100% -100% -100% long 134/s 7707% -- -71% -79% -81% classic 468/s 27047% 248% -- -26% -33% str 632/s 36579% 370% 35% -- -9% translate 695/s 40233% 417% 49% 10% -- C:\test>1046579 -N=2**30 1073741824 (warning: too few iterations for a reliable count) (warning: too few iterations for a reliable count) s/iter str translate str 1.96 -- -21% translate 1.54 27% --

      The modified code:


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        I am confused. Is not $_[0] aliased to the function argument? Why using all those references and dereferences?
        Moreover, running your code with N=2**29, I am still getting
        single 6.13e-03/s -- -100% -100% -100% -100% long 2.97/s 48381% -- -1% -35% -58% translate 3.01/s 48989% 1% -- -35% -58% classic 4.60/s 74981% 55% 53% -- -36% str 7.14/s 116486% 140% 137% 55% --

        With 2**30, it dies with

        Substitution loop at ./7.pl line 10.

        Update: This is perl 5, version 16, subversion 0 (v5.16.0) built for x86_64-linux-thread-multi

        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-03-29 06:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found