You have a benchmark showing very little cost for blessing objects, but the actual cost of a simple getter compared with a hash access may be the thing of concern. Well, probably it isn't. It certainly isn't the more than 144,000% hit others have suggested. The following benchmark result indicates at worst a factor of five cost between a getter and a hash access used in a simple assignment:

Rate derived baseobj hash derived 1641/s -- -0% -79% baseobj 1649/s 0% -- -79% hash 7876/s 380% 378% --
#!/usr/bin/perl use strict; use warnings; package ClassBase; sub new { my ($class, $hash) = @_; return bless $hash, $class; } sub getter { my ($self) = @_; return $self->{1}; } package Derived; use parent -norequire => 'ClassBase'; sub new { my ($class, $hash) = @_; return $class->SUPER::new ($hash); } package main; use Benchmark qw(cmpthese); my %hash = 1 .. 10; my $baseobj = ClassBase->new (\%hash); my $derived = Derived->new (\%hash); my $dump; cmpthese(-1, { baseobj => sub {$dump = $baseobj->getter() for 1 .. 1000}, derived => sub {$dump = $derived->getter() for 1 .. 1000}, hash => sub {$dump = $hash{1} for 1 .. 1000}, } );
True laziness is hard work

In reply to Re: Time efficiency of object creation in Perl (or the "bless" function) by GrandFather
in thread Time efficiency of object creation in Perl (or the "bless" function) by kikumbob

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.