Array objects in Perl 5.6.0+ 
Author Message
 Array objects in Perl 5.6.0+

Hi,

   I wonder how speed and memory usage of array objects and hash
objects [1] compare in Perl 5.6.0 and/or above. Are there any test
results (considering big and large objects) for that available?

[1] a simple example to define these terms:

    sub arrayObject::new { bless [], shift         }
    sub arrayObject::get { shift->[_key_]          }
    sub arrayObject::set { shift->[_key_] = shift  }

    # where _key_ is a numeric constant; versus

    sub hashObject::new { bless {}, shift          }
    sub hashObject::get { shift->{'_key_'}         }
    sub hashObject::set { shift->{'_key_'} = shift }

I remember an TPJ issue where testings with an eraly version of Perl
5.005 showed up to +20% speed and -40% memory usage for array objects.

Why are array objects that rarely used?
--

am Badedeich 7 } Telefon: +49(0)4667/981028 { http://www.*-*-*.com/
25899 Dagebll { PGP Pub. KeyID: 0xA4357E78 } http://www.*-*-*.com/



Tue, 07 Oct 2003 15:12:43 GMT  
 Array objects in Perl 5.6.0+
Bjoern Hoehrmann schrieb:

Quote:

> Hi,

>    I wonder how speed and memory usage of array objects and hash
> objects [1] compare in Perl 5.6.0 and/or above. Are there any test
> results (considering big and large objects) for that available?

> [1] a simple example to define these terms:

> I remember an TPJ issue where testings with an eraly version of Perl
> 5.005 showed up to +20% speed and -40% memory usage for array objects.

You can find a good comparisson about different things to bless in Damian
Conway's "Object Oriented Perl".

You have to consider that using objects in Perl is a choice of convenience
over speed. Choosing a Hash over an Array is the same kind of choice, so
its likely to make both of the choices together.

Hash lookups will always be slower than Array lookups, so there should
not be
a significant difference in speed between Perl 5.6 and earlier versions.

Bye,

->malte



Tue, 07 Oct 2003 23:24:05 GMT  
 Array objects in Perl 5.6.0+


Quote:
>Bjoern Hoehrmann schrieb:

>> Hi,

>>    I wonder how speed and memory usage of array objects and hash
>> objects [1] compare in Perl 5.6.0 and/or above. Are there any test
>> results (considering big and large objects) for that available?

>> [1] a simple example to define these terms:

>> I remember an TPJ issue where testings with an eraly version of Perl
>> 5.005 showed up to +20% speed and -40% memory usage for array objects.

>You can find a good comparisson about different things to bless in Damian
>Conway's "Object Oriented Perl".

>You have to consider that using objects in Perl is a choice of convenience
>over speed. Choosing a Hash over an Array is the same kind of choice, so
>its likely to make both of the choices together.

...

There are so many apples-to-oranges comparisons in this conversation
I've become completely lost.  Just what is being claimed here?

It sounds like the first writer (apparently Bjoern Hoehrmann) claimed
that in an "early version" of Perl, array objects are 20% faster and
40% smaller than something else.  (Plain old arrays?)  Yet the second
writer is claiming that using objects is a choice of convenience over
speed.

What is being compared to what here?  These vague discussions without
explaining what exactly is being compared don't communicate their
points well.
--

Please consider boycotting Amazon.com for their outrageous abuse of
their patents!  Details at http://www.fsf.org/philosophy/amazon.html



Wed, 08 Oct 2003 00:15:16 GMT  
 Array objects in Perl 5.6.0+

Quote:
> Why are array objects that rarely used?

Because nobody likes asking for $self->[57] instead of $self->{color}?

The trick where you create a constant named '__color__' whose
value is 57 works for a while, until you have two different classes
that both have a 'color' member; then you lose.

Similarly, hashes can be made to work with multiple inheritance, but
arrays can't.



Wed, 08 Oct 2003 01:25:23 GMT  
 Array objects in Perl 5.6.0+

Quote:

> Similarly, hashes can be made to work with multiple inheritance, but
> arrays can't.

Oh, don't say "can't".  Arrays can be concated.
If you can use tricks like '__color__', you
can also have a per-class starting offset, etc.

--
John Porter



Fri, 10 Oct 2003 22:26:05 GMT  
 Array objects in Perl 5.6.0+


: The trick where you create a constant named '__color__' whose
: value is 57 works for a while, until you have two different classes
: that both have a 'color' member; then you lose.

Not necessarily.  See

    <URL:http://home.hiwaay.net/~gbacon/perl/array-obj.html>

for an implementation that allows different classes to use the same
name for different attributes.

: Similarly, hashes can be made to work with multiple inheritance, but
: arrays can't.

Right.  That's because the chain from a node to any other node (say
the root) is unique in a tree, but this isn't the case for graphs in
general.

Greg
--
Chef:    Haven't you ever heard of the Emancipation Proclamation?
General: I don't listen to hip-hop.



Fri, 10 Oct 2003 23:44:37 GMT  
 Array objects in Perl 5.6.0+

Quote:

> > Similarly, hashes can be made to work with multiple inheritance, but
> > arrays can't.

> Oh, don't say "can't".  Arrays can be concated.
> If you can use tricks like '__color__', you
> can also have a per-class starting offset, etc.

No, because then each class has to know in advance what its subclasses
will be, and what other classes its subclasses will inherit from.

And you end up with base classes with constructors like this:

        package X;

        sub new {
          my $pack = shift;
          my $self = [];
          $self->[1539] = shift;
          bless $self => $pack;
        }

        sub color {
          return $_[0][1539];
        }

These X objects are represented by an array of 1539 undefs followed by
a color name.  Not very pleasant.



Sat, 11 Oct 2003 00:17:40 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. >>BDE SQL Group By Clause Bug ?<<

2. hash of objects vs array of objects

3. Pb with an array in a PERL Object (bis)

4. PB with an array in a PERL object

5. Pb with an array in a PERL Object (bis)

6. PB with an array in a PERL object

7. arrays as part of perl module objects?

8. Pb with an array in a PERL Object (bis)

9. PB with an array in a PERL object

10. Associative arrays as object data members in Perl 5

11. Make 300% profit or double your money in a month FMAWDSGE

12. SQL Queries

 

 
Powered by phpBB® Forum Software