Re: Speed of increment operators



axel@xxxxxxxxxxxxxxxxxxxxxx wrote:
Dr.Ruud <rvtol+news@xxxxxxxxxxxx> wrote:
The first two lines of my smaller Perl scripts often look like:

#!/usr/bin/perl
use strict; use warnings; ++$|;

On a slightly different track, is there any different in execution
speed between ++$i and $i++ in Perl. I seem to remember that there
was such a difference in C++ but may be mistaken.

perl -MO=Deparse -e'$x = 5; $x++; ++$x;'
$x = 5;
++$x;
++$x;
-e syntax OK

Seeing as how Perl optimizes away the post-fix notation when called in
a void context, I'm going to go on a limb and say "no, it doesn't make
a difference". In any case in which Perl would not optimize it away,
then you're doing something differently when you call one instead of
the other, and so speed should not be your concern.

Paul Lalli

.



Relevant Pages

  • Re: How perl program execution happened ?
    ... But i want clear idea about how the perl ... program execution was happened. ... perl compiles the script, but as soon as it compiles a complete ... here)) and reads and starts compiling the module (handling BEGIN ...
    (perl.beginners)
  • Re: Trouble running a unix command with a subroutine call
    ... the most infamous and most imaginative Perl programmer ever! ... During all my years of Perl programming, not once have I used subroutinesyntax. ... I find the author of this FAQ to be intellectually insulting by his indicating ...
    (comp.lang.perl.misc)
  • Re: print @{1} versus print @{11}
    ... >> -e syntax OK ... The name of a perl variable can be enclosed in if necessary ... > These are not idle questions by the way ... ... "Reply" at the bottom of the article headers. ...
    (comp.lang.perl.misc)
  • Re: CASE...ENCASE Query...
    ... BBC ... BASIC must always "handle syntax errors throughout execution" in order ... I'd happily wait a little longer for the cruncher ...
    (comp.sys.acorn.programmer)
  • Re: CASE...ENCASE Query...
    ... BBC ... BASIC must always "handle syntax errors throughout execution" in order ... I'd happily wait a little longer for the cruncher ...
    (comp.sys.acorn.programmer)