Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^3: Using 'keys' on a list

by Marshall (Canon)
on Jul 02, 2021 at 19:27 UTC ( #11134599=note: print w/replies, xml ) Need Help??


in reply to Re^2: Using 'keys' on a list
in thread Using 'keys' on a list

I don't think a benchmark makes much sense with this very small contrived example. Most of the hashes I work with have a lot more than 2 keys! In general passing back a single thing (ref to a hash) is gonna be much faster than passing back a list of key/value pairs so that the hash can be re-created by the caller. The bigger the hash is, the more apparent this speed difference is going to be. With 2 keys, there isn't a huge difference in a practical sense (impact on total application performance might not be anything of note). With say 80,000 keys, there is a lot of difference between the 2 methods of passing back an entire hash!

Now if all you need are the keys instead of the full hash, yes, there won't be much of a difference at all. The sub could traverse the hash and make a list. Or the sub gives the caller the ref and the caller traverses the hash to make a list. The effect and performance will be about the same. Sometimes these very short snippets of code don't reflect what is going on the in overall application. The code as formulated is a rather odd idea, pass a list of key/value pairs to the sub, only to ask what the keys are? Why have to make a hash in the first place? I dunno.

Replies are listed 'Best First'.
Re^4: Using 'keys' on a list
by Anonymous Monk on Jul 02, 2021 at 21:08 UTC
    I don't think a benchmark makes much sense ... The effect and performance will be about the same.

    there you go again making claims about performance when you haven't run the benchmarks

      Ok, what would you have me benchmark? Why don't you do it yourself?

      Update:
      If you need access to a complete hash, it is completely clear that returning a reference to a hash which has been created already is much more efficient than causing the hash to be re-created from a list. If you claim that is not true, then you need to provide some benchmarks yourself! That duck just doesn't fly.

      I guess we are talking about returning ONLY the keys from a hash table, that which is created in a sub? Or what? The sub can make a list of those keys itself or it can pass a ref to its internal hash for the calling sub to do the same. That computational effort will be similar.

      What are you talking about? What kind of benchmark do you propose?

        Why don't you do it yourself?

        uh, because *you're* the one making claims about performance without benchmarks...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2021-12-08 03:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (34 votes). Check out past polls.

    Notices?