Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Some more variations for you to include in the mix...

    Params::Util::_INSTANCE has long done Scalar::Util::blessed($foo) and $foo->isa('bar'), I'd be interested to see how much overhead the extra function call adds.

    Also, try substituting UNIVERSAL::can($foo, 'can') for blessed($foo)
    • So you want a fully qualified call to blessed instead of my importing it? Or did you miss that I had called blessed? UNIVERSAL::can('isa') is interestesting, but I'm sure that won't be much faster. I've added both of those (the fully qualified Scalar::Util::blessed() is called 'fqblessed', of course).

      Benchmark: timing 200000 iterations of blessed, can, eval, fqblessed, stringify, universal, unpack...
         blessed:  1 wallclock secs ( 0.86 usr +  0.00 sys =  0.86 CPU) @ 232558.14/s (n=200000)
             can:  1 wallclock secs ( 0.86 usr +  0.00 sys =  0.86 CPU) @ 232558.14/s (n=200000)
            eval:  2 wallclock secs ( 1.72 usr +  0.01 sys =  1.73 CPU) @ 115606.94/s (n=200000)
      fqblessed:  1 wallclock secs ( 0.86 usr +  0.00 sys =  0.86 CPU) @ 232558.14/s (n=200000)
      stringify:  1 wallclock secs ( 1.09 usr +  0.00 sys =  1.09 CPU) @ 183486.24/s (n=200000)
      universal:  1 wallclock secs ( 0.60 usr +  0.00 sys =  0.60 CPU) @ 333333.33/s (n=200000)
          unpack:  1 wallclock secs ( 1.35 usr +  0.00 sys =  1.35 CPU) @ 148148.15/s (n=200000)

      So for my special case use, I can use UNIVERSAL::can and simply declare the class final (but it's an internal class, so that's OK). Otherwise, blessed plus isa is the fastest and most correct out of the alternatives I've tried.

      • No, I meant you should include the overhead of doing it the fastest way (which Params::Util does) but with an extra function call of calling Params::Util::_INSTANCE itself.