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.


Comment on Re^2: A benchmark
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]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2015-10-05 02:34 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (106 votes), past polls