in reply to Re^4: Faster creation of Arrays in XS?
in thread Faster creation of Arrays in XS?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Faster creation of Arrays in XS?
by wollmers (Scribe) on Jun 22, 2015 at 14:49 UTC | |
by BrowserUk (Patriarch) on Jun 22, 2015 at 15:00 UTC | |
by wollmers (Scribe) on Jun 23, 2015 at 07:19 UTC | |
by BrowserUk (Patriarch) on Jun 23, 2015 at 11:39 UTC |