Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Data structures benchmark(pack vs. arrays vs. hashes vs. strings)

by AnomalousMonk (Archbishop)
on Dec 10, 2011 at 00:47 UTC ( [id://942751]=note: print w/replies, xml ) Need Help??


in reply to Data structures benchmark(pack vs. arrays vs. hashes vs. strings)

I have serious, basic confusion about your question. According to my understanding of Serialization or Marshalling, only the pack/unpack approach you show qualifies at all. Creating an anonymous array or hash and then accessing an element or elements of the array or hash does not qualify because it cannot be done, e.g., over a network or with an intervening step of storage to a disk.

Can you clarify your definitions and/or application?

  • Comment on Re: Data structures benchmark(pack vs. arrays vs. hashes vs. strings)

Replies are listed 'Best First'.
Re^2: Data structures benchmark(pack vs. arrays vs. hashes vs. strings)
by spx2 (Deacon) on Dec 10, 2011 at 00:56 UTC
    the purpose is to take a string, split it and store it in memory in such a way that you can pass it around and not need to split it again when receiving it in some other part of the program.
      the purpose is to take a string, split it and store it in memory in such a way that you can pass it around and not need to split it again when receiving it in some other part of the program.

      Then nothing will be as fast as constructing an array of arrays and passing a reference to it around. It could not be so.

      Reading between the lines, your main problem seems to be that yoo are inisting on copying the subarrays to local named scalars each time before using them, rather than just using them in-situ.

      Ie. You are doing something like:

      sub process { my( $AoA, $thingToProcess ) = @_; my( $v1, $v2, $v3, $v4, $v5, $v6, $v7 ) = @{ $AoA->[ $thingToProce +ss ] }; my( $r1, $r2, $r3, $r4, $r5, $r6, $r7 ) = ( ... some calculation(s +) involving $v1, $v2, $v3, $v4, $v5, $v6, $v7 ... ); @{ $AoA->[ $thingToProcess ] } = ( $r1, $r2, $r3, $r4, $r5, $r6, $ +r7 ); return; }

      When you could be doing:

      sub process { my( $AoA, $thingToProcess ) = @_; $AoA->[ $thingToProcess ][ 3 ] = $AoA->[ $thingToProcess ][ 1 ] * + $AoA->[ $thingToProcess ][ 2 ]; ... return; }

      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.

      The start of some sanity?

        this is correct. however, writing each time $AoA->[ $thingToProcess ][ something ] could lead to hard to understand code.

        also, if in the benchmarks, I use every time the "copying the subarrays to local named scalars" , these cancel themselves out, so basically the benchmark is still valid from this point of view, do you agree ?

      But if you are going to be operating entirely within a program and not, e.g., storing to disk or transmitting to another computer over a network, why not just pass array or hash references (or object references) around? Again, I don't understand the application.

        there's a big amount of strings that need to be processed(the split and store in some data structure thing), so storing it in a hash is not very optimal, turns out from the benchmarks an array would be faster. but I was expecting pack/unpack to be faster since it just packs it into a very simple datastructure and then unpacks it the same way, not needing so complex data structures such as hashes/arrays, instead.. it would just store everything as binary data. so that's why I was expecting that to be faster.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://942751]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2025-07-15 13:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.