user-pic

QM

  • About: Quantum Mechanics: The dreams stuff is made of!
Subscribe to feed Recent Actions from QM

  • Diab Jerius commented on Extracting values from a list of (key, value) pairs

    @QM: You've raised some good points.

    • Yes, @k would have been a better choice than @v. My mistake. I'd fix the code, but then your comment would have no context.
    • Why a short variable name? The focus here is on the inner parts of the algorithm. Longer variable names would add visual clutter and detract from the comparison. Brevity is not always a curse.
    • The short and bizarre tags are simply because if they were longer the comparison table at the bottom would be too wide and would wrap due to the formatting in …
  • Graham Knop commented on Extracting values from a list of (key, value) pairs

    There is a small mistake in your code. @N has an odd number of elements. pairkeys will warn about this if warnings are on.

    Another option for this is doing an array slice:

    @N[ map $_*2, 0..(@N/2)-1 ]
    It's slower than several other options though.

  • Aristotle commented on Extracting values from a list of (key, value) pairs

    I wonder how idxa performs if you add a $#v = $#N / 2; before the loop.

  • Diab Jerius commented on Extracting values from a list of (key, value) pairs

    @Graham Knop: I've fixed the code; thanks.

    @Aristotle: It actually seems to slow it down by a bit. Sequential runs with with your suggestion implemented, followed by the original code give:

    with: 1002/s 1016/s
    original: 1049/s 1075/s

    The difference between the two is probably significant within the noise of the measurements.

  • mascip commented on Extracting values from a list of (key, value) pairs

    Have you tried Var::Pairs, written by Damian Conway? It doesn't have a subroutine to extract all keys, but it's very god for loops:

    for my $next (pairs @array) {
    say $next->index, ' has the value ', $next->value;
    }

Subscribe to feed Responses to Comments from QM

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl and offering the modern features you’ve come to expect in blog platforms, the site is run by Dave Cross and Aaron Crane, with a design donated by Six Apart, Ltd.