Efficiency/New Perl Book: return @array vs \@array 
Author Message
 Efficiency/New Perl Book: return @array vs \@array

<<

 use Benchmark;
 timethis(1000000, "iso_xy()");

  sub iso_xy {


                          #the benchmark take 50% longer!
 }

All you are doing in this benchmark is to return the same array
over and over again, without using it. Perl notices the fact
that you are not using the return value, so it doesn't do
anything internally.


and notices that you don't do anything with that scalar, so it
junks it .. but meanwhile it incurs the cost of creating that
scalar.

When benchmarking make sure you do something with the return value.
In a real system, if you said

you incur the cost of an array copy,
whereas if you said,
  $foo = iso_xy(), you only incur the cost of a scalar copy.

- Sriram

________________________________________________________________________
Principal Engineer      WebLogic, San Francisco        www.weblogic.com
"Advanced Perl Programming" : http://www.*-*-*.com/



Tue, 07 Mar 2000 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Efficiency/New Perl Book: return @array vs \@array?

2. Efficiency of returned arrays

3. Perl 5.001e subroutine returns length of array instead of array

4. array vs. array question

5. ?: Array Reference vs Anon Array Reference

6. printf(@array) vs sprintf(@array)

7. Returning an array of arrays and accessing it

8. returning an array of arrays from a subroutine

9. Does deref of array ref instantiate new array?

10. URGENT: Hash in Hash, Array in Array, Array in Hash, Hash in Array

11. hash efficiency and key/value/array reading file

12. Efficiency of eval (emulating multidimentional arrays)

 

 
Powered by phpBB® Forum Software