Yes, 2 elements 50 times.

Yes, but it is still the fastest of all the methods you've benchmarked:

unpack for: 1 wallclock secs ( 1.01 usr + 0.00 sys = 1.01 CPU) + @ 49504.95/s (n=50000) unpack for push: 2 wallclock secs ( 1.84 usr + 0.00 sys = 1.84 CPU) + @ 27173.91/s (n=50000) unpack while: 1 wallclock secs ( 0.84 usr + 0.00 sys = 0.84 CPU) + @ 59523.81/s (n=50000) <<<< This is fastest unpack while push: 2 wallclock secs ( 1.75 usr + 0.00 sys = 1.75 CP +U) @ 28571.43/s (n=50000) unpack while single: 1 wallclock secs ( 1.28 usr + 0.00 sys = 1.28 +CPU) @ 39062.50/s (n=50000)

If you used cmpthese() instead of timethese(), it sorts the tests for you and the best result becomes obvious.

But the things you've benchmarked against make no sense. Why would you unpack two at a time only to push to an array? You might just have well cut out the middle man and built the array to start with.

Or if you really insist on building an array from the packed string, let perl do it for you:  my @array = unpack 'V*', $packed;

What you should be comparing is the time taken to construct and return an AoAs and then access the elements (use) that AoAs; versus the time taken to construct and return the packed string and then access the elements (use) that packed string.

Throwing the cost of building another array into the timing makes no sense at all.

With bitmaps it would be an array of 2 scalars (2 x 64-bit IVs, 53 bits used in the original test case).

I seriously doubt it is cheaper to pack the information into a bitstring at the C level, and then unpack it again at the Perl level than to build a packed array of integers at the C level and then unpack them at the perl level.

I know from experience that accessing individual bits in Perl -- whether using per-bit calls to vec; or compound boolean expressions: ( $bits & (1 << $pos) ) >> $pos -- is far slower than unpacking integers from a packed array.

And it would take a full end-to-end (perl->C->perl) benchmark of both methods to convince me otherwise.

But, its your code. Good luck.


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'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!

In reply to Re^5: Faster creation of Arrays in XS? by BrowserUk
in thread Faster creation of Arrays in XS? by wollmers

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.