Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Faster creation of Arrays in XS?

by wollmers (Scribe)
on Jun 21, 2015 at 20:56 UTC ( [id://1131401]=note: print w/replies, xml ) Need Help??


in reply to Re: Faster creation of Arrays in XS?
in thread Faster creation of Arrays in XS?

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.

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

    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://1131401]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-03-28 21:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found