For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > January 2006 > Re: How to improve speed of returning value from calling method on an array of object









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: How to improve speed of returning value from calling method on an array of object
Paul Lalli

2006-01-10, 4:02 am

Sai Tong wrote:

> I have an array of many objects and I want to call a method on
> each of these objects and the save the returned values into an array:
>
> my @return_values;
> foreach my $retrievedObject (@array_of_objects) {
> push (@return_values , $retrievedObject->method );
> }
>
> The problem is this code runs too slowly for a large array of objects.
> Its seems that it might be a little too slow to "push" each
> returned value into @return_values . Can anyone suggest the best way to
> improve the speed of putting the returned value of
> each object into an array?


I find it drastically unlikely that "push" is the cause of your slow
down. On what basis do you make this assumption?

Try profiling your code, using the Devel::DProf module (standard with
Perl). That will tell you where your code is spending the most time.
I'm willing to bet it's in the method call, not the push operation.

Paul Lalli

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com