Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Faster creation of Arrays in XS?

by BrowserUk (Patriarch)
on Jun 21, 2015 at 19:52 UTC ( [id://1131372]=note: print w/replies, xml ) Need Help??


in reply to Faster creation of Arrays in XS?

Why not skip the AoAs and return a string with two delimiters? eg. "3:4 6:3 8:3";

It seems to be just as easy, and probably faster to do:

my $diffs = diff( .... ); for my $diff ( split ' ', $diffs ) { my( $start, $len ) = split ':', $diff; ## use start / len }

As it is:

my $ref = diff( ... ); for my $pair ( @{ $ref } ) { my( $start, $len ) = @{ $pair }; ## use start / len }

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!

Replies are listed 'Best First'.
Re^2: Faster creation of Arrays in XS?
by wollmers (Scribe) on Jun 21, 2015 at 20:56 UTC

    This is magnitudes slower:

    #!perl use 5.006; use strict; use warnings; use Benchmark qw(:all) ; use Data::Dumper; my $diffs = join(' ', (map { "$_:$_" } (0..49))); timethese( 50_000, { 'split' => sub { my $LCS = []; for my $diff ( split ' ', $diffs ) { my( $x, $y ) = split ':', $diff; #push @$LCS, [$x,$y]; } }, }); ############ ~/github/LCS-XS/xt$ perl split.t Benchmark: timing 50000 iterations of split... split: 2 wallclock secs ( 2.04 usr + 0.00 sys = 2.04 CPU) @ 24 +509.80/s (n=50000)

    24 kHz without push, with push 11 kHz.

      The idea was to build the string in XS and give that to the caller; not build a string and then build the AoAs from the string; which of course will be slower as your still building the AoAs, but also building and the breaking down the string.

      Ie. Build the string instead of the AoAs in XS; and give the caller the string instead of the AoAs; thus avoiding the building of the AoAs entirely.

      Be sure to preallocate the string to (even much) bigger than will be required and then use set CUR to trim to the final size.


      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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1131372]
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: (2)
As of 2024-04-20 03:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found