Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > which is faster ?

Reply
Thread Tools

which is faster ?

 
 
George Mpouras
Guest
Posts: n/a
 
      08-04-2011
$#array
scalar @array or
my $n = @array ?
 
Reply With Quote
 
 
 
 
J. Gleixner
Guest
Posts: n/a
 
      08-04-2011
On 08/04/11 21:30, George Mpouras wrote:
> $#array
> scalar @array or
> my $n = @array ?


perldoc Benchmark

Sounds like premature optimization, to me.
 
Reply With Quote
 
 
 
 
Dr.Ruud
Guest
Posts: n/a
 
      08-04-2011
On 2011-08-04 23:30, George Mpouras wrote:

> which is faster ?
>
> $#array
> scalar @array or
> my $n = @array ?


If magic or tie or operator-overload is not involved, there will hardly
be any difference in speed. Just benchmark to find out.

$#array is the highest index of @array. The other two are about the
number of elements. $[ gives the minimum index which is normally 0.

--
Ruud
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      08-04-2011
George Mpouras <> wrote:
>$#array
>scalar @array or
>my $n = @array ?


IMNSHO you are asking the wrong question. Because each of these three
code pieces has a different semantic the right question would be "Which
code piece has the right semantic for my algorithm?"

jue
 
Reply With Quote
 
robin
Guest
Posts: n/a
 
      08-15-2011
On 04-Aug-2011 3:30 PM, George Mpouras wrote:
> $#array
> scalar @array or
> my $n = @array ?

I assume with strict the my one with work faster, I think the strict
pragma makes it faster perl.
-r
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      08-15-2011
robin <> wrote:
>On 04-Aug-2011 3:30 PM, George Mpouras wrote:
>> $#array
>> scalar @array or
>> my $n = @array ?

>I assume with strict the my one with work faster, I think the strict
>pragma makes it faster perl.


Your statement can be interpreted in two ways:
- I assume with strict the my one with work faster than the other two
options shown
- I assume with strict the my one with work faster than without using
strict

Which one is it?

jue
 
Reply With Quote
 
Rainer Weikusat
Guest
Posts: n/a
 
      08-15-2011
robin <> writes:
> On 04-Aug-2011 3:30 PM, George Mpouras wrote:
>> $#array
>> scalar @array or
>> my $n = @array ?

> I assume with strict the my one with work faster, I think the strict
> pragma makes it faster perl.


According to the corresponding documentation, access to 'my' variables
should be faster than acceses to 'other variables' and I expect this
to be actually true because a variable declared with my reside in a
scope-specific array and are accessed by array index while 'package
globals' require a hash lookup in the symbol table hash of the package
they belong to. But that's not at all related to 'strict' which
reconfigures the Perl compile by modifying the variable $^H and has no
runtime effects. (AFAIK).

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Microcontrollers: which one ? which language ? which compiler ? The Jesus of Suburbia NZ Computing 2 02-11-2006 06:53 PM
Which is faster in ASIC: 2-input AND gate or a 2-input multiplexer Weng Tianxiang VHDL 12 08-11-2005 10:50 AM
Static Routing Vs EIGRP, Which is Faster? AM Cisco 3 11-10-2004 04:22 AM
Cisco router fast ethernet vs fddi which is faster and stable JOHN Cisco 0 11-22-2003 03:31 AM
Which is faster? Dim dv As New DataView(session("myDataTable")) or CType(session("myDataTable")) Andreas Klemt ASP .Net 1 07-23-2003 12:18 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57