Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
The remaining difference in memory is due to the Perl version knowing exactly how big the array will be from the start (because the whole list is assigned in one go):
FILL = 999 MAX = 999

The C version causes the arrays to grow and leaves space for growth:

FILL = 999 MAX = 1021

By pre-extending the arrays,

SV *make_aoa_c( int n_rows, int n_cols ) { int i, j; char *foo = "foo"; AV *table = newAV(); av_extend(table, n_rows-1); /* <---------- */ for ( i = 0; i < n_rows; ++i ) { AV *row = newAV(); av_extend(row, n_cols-1); /* <---------- */ for ( j = 0; j < n_cols; ++j ) { av_push( row, newSVpv( foo, 0 ) ); } av_push( table, newRV_noinc( row ) ); } return newRV_noinc( table ); }

both the Perl and the C data structures are identical.

FILL = 999 MAX = 999

and the process that calls the C version uses less memory (perhaps from reduced stack usage?)

$ perl 1: 78688 (184871 us) 2: 78696 (298376 us) 3: 78696 (196999 us) 4: 78696 (204391 us) 5: 78696 (225786 us) $ perl use_xs 1: 78604 (321481 us) 2: 78616 (360377 us) 3: 78616 (219468 us) 4: 78616 (211587 us) 5: 78616 (209231 us)

The times are comparable, but note this it a busy machine.

In reply to Re^3: Inline::C's AoA is much bigger than Perl's by ikegami
in thread Inline::C's AoA is much bigger than Perl's by tlm

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (5)
    As of 2018-02-25 16:21 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (314 votes). Check out past polls.