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

Re^2: A benchmark

by Jeffrey Kegler (Hermit)
on Oct 07, 2007 at 15:07 UTC ( #643288=note: print w/replies, xml ) Need Help??

in reply to Re: A benchmark
in thread Unique numeric ID for reference?

Since my test data has exactly one sort record, any ID number would be unique. :-) I'm trying to focus on the per-record time for a pre-pass to a sort, so I think a single record database captures those aspects of the problem I'm focused on.

I ran more numbers, by the way, looking at what happens if you have to deal with potentially undefined records. It gets complicated depending on whether you can turn off warnings, if you have to explicitly test for undefinedness, whether you need multiple levels of, etc., etc. The numeric solution ($ref+0) and the indirection-to-unique-identifier solution ($ref->[0]) run neck to neck, continually swapping first and second place with every small change in the assumptions.

My conclusion is that they're close enough in terms of efficiency that even in time-efficiency driven situations, you can let other factors (readability, space-efficiency, etc.) decide.

I've coded it up using your suggestion of forcing the reference to numeric ($ref+0). Like I say, I decided efficiency was a tie, and by using the references as the subkesy I save the extra logic needed to create and track an extra data field.

I do wonder why in the refaddr code in non-XS Scalar::Util, the code stringifies the reference then pulls a number out with a regex. As far as I can tell in terms of complexity and time-efficiency, that's clearly inferior to forcing the reference to numeric.


Replies are listed 'Best First'.
Re^3: A benchmark
by Juerd (Abbot) on Oct 08, 2007 at 12:49 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://643288]
[Discipulus]: choroba's tk cb client become incerdibly stable after https switch; it's a coincidence?
[Discipulus]: it hits some read timeouts but reconnect without issues
erix googles incerdibly and finds incredibly (translate is cleverder than I am)

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2018-06-19 07:30 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (111 votes). Check out past polls.