in reply to Re: Faster creation of Arrays in XS?
in thread Faster creation of Arrays in XS?
BrowserUK: Unpack in your above code also creates a list, which seems to be the same bottleneck. Benchmarks are in the same range.
Also tried List::Util::pairs(), which benchmarks a little faster. Maybe I can copy and inline this part of C code.
What I maybe will do now is providing different formats, AoA [2][L], AoA[L][2] and 2 bitstrings (match-index). Bitstrings should be very fast, but not so convenient to process. Perl5 does not have the functions lsb (index of lowest significant bit) and msb, which Perl6 has.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Faster creation of Arrays in XS?
by BrowserUk (Patriarch) on Jun 22, 2015 at 11:02 UTC | |
Unpack in your above code also creates a list, Only a list of 2 elements? That why I showed using substr to nibble the packed array in pairs. 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!
| [reply] |
by wollmers (Scribe) on Jun 22, 2015 at 11:52 UTC | |
Yes, 2 elements 50 times.
With bitmaps it would be an array of 2 scalars (2 x 64-bit IVs, 53 bits used in the original test case). | [reply] [d/l] |
by BrowserUk (Patriarch) on Jun 22, 2015 at 12:45 UTC | |
Yes, 2 elements 50 times. Yes, but it is still the fastest of all the methods you've benchmarked:
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!
| [reply] [d/l] [select] |
by wollmers (Scribe) on Jun 22, 2015 at 14:49 UTC | |
by BrowserUk (Patriarch) on Jun 22, 2015 at 15:00 UTC | |
| |
by BrowserUk (Patriarch) on Jun 22, 2015 at 14:09 UTC | |
This is what I mean by an end-to-end benchmark:
It surprised me how badly the two delimiters idea worked out; and how fast simply returning a list was. 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!
| [reply] [d/l] |