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

Re^4: Efficient bit-twiddling in Perl.

by BrowserUk (Patriarch)
on Mar 01, 2013 at 12:40 UTC ( [id://1021241]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Efficient bit-twiddling in Perl.
in thread Efficient bit-twiddling in Perl.

Your benchmark is not very realistic. As $n doesn't vary, you are completely ignoring the effect of the CPU cache misses that the lookup table may introduce.

The version of my benchmark I posted was the one I use -- in conjunction with -N=1 and uncommenting the print "@_"; -- to check that the output from all the methods is correct.

For timing runs, I operate on the loop counter $_, which when -N=10e6, is enough to exercise the full range of the table 38 times.

And I still get 20%+ improvement from the AoAs lookup:

Results

C:\test>1021064 Shift&and took: 0.000000606833 seconds Lookup took: 0.000000485629 seconds Lookup2 took: 0.000000669586 seconds (un)pack took: 0.000007564075 seconds

In general, I've found it very difficult to detect, much less measure any discernible effect from cpu caching in perl code on my machine. It shows up readily in tight loops in C code, but Perl's memory allocation is so cache unfriendly that it rarely seems to come into play.

I would be interested to see the output from the above on your machine if you have a coupe of minutes.


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.

Replies are listed 'Best First'.
Re^5: Efficient bit-twiddling in Perl.
by salva (Canon) on Mar 01, 2013 at 13:25 UTC
    $ perl /tmp/1021241.pl Shift&and took: 0.000000844352 seconds Lookup took: 0.000000794679 seconds Lookup2 took: 0.000000945985 seconds (un)pack took: 0.000007257208 seconds

      Less, but still a saving. Thanks. What cpu are you using?

        AMD Athlon(tm) 64 X2 Dual Core Processor 4000+ (IIRC, this is a 2GHz processor)
Re^5: Efficient bit-twiddling in Perl.
by Tux (Canon) on Mar 01, 2013 at 14:05 UTC
    tables generated sample data generated Shift&and took: 0.000000283640 seconds Lookup took: 0.000000553529 seconds Lookup3 took: 0.000000308301 seconds Lookup4 took: 0.000000435056 seconds Lookup5 took: 0.000000487484 seconds Lookup6 took: 0.000000454496 seconds Lookup7 took: 0.000000476669 seconds Linux 3.4.28-2.20-desktop [openSUSE 12.2 (Mantis)] x86_64 Xeon(R) CPU E5-1650 0 @ 3.20GHz/1200(12) x86_64 16009 Mb This is perl 5, version 16, subversion 2 (v5.16.2) built for x86_64-li +nux-ld

    I think that proves my point in Re^3: Efficient bit-twiddling in Perl.


    Enjoy, Have FUN! H.Merijn
      I think that proves my point in Re^3: Efficient bit-twiddling in Perl.
      I am stunned by the 20% gain you get, and wonder if that would differ per perl version and/or architecture.

      It absolutely will, but as I said in the OP, this is for me, on my hardware. Not an exemplar for anyone else.


      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.
Re^5: Efficient bit-twiddling in Perl.
by Tux (Canon) on Mar 01, 2013 at 14:07 UTC
    Shift&and took: 0.000000288148 seconds Lookup took: 0.000000252554 seconds Lookup2 took: 0.000000339390 seconds (un)pack took: 0.000002284377 seconds

    Enjoy, Have FUN! H.Merijn

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-04-18 06:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found