develooper Front page | perl.perl5.porters | Postings from May 2015

Re: Curiosity about "do {;}" vs. "{;}" realtime cost

Thread Previous | Thread Next
May 19, 2015 21:12
Re: Curiosity about "do {;}" vs. "{;}" realtime cost
Message ID:
Glenn Golden wrote:
>I'd have guessed that both constructs would get optimized away during
>compilation, but evidently "{;}" incurs some execution overhead that
>"do {;}" does not.

A bare block is semantically treated as a loop that executes only once.
It incurs the overhead of setting up the context frame that supports
dynamic operators such as "next".  A do block, on the other hand, provides
only scoping, so is much lighter at runtime.  There's also optimisation
that applies only to do blocks: the dynamic scoping ops will be elided
if not needed, as in this case.  I suppose in theory the empty bare
block could be similarly optimised away, but the applicability would be
more limited than what is done with do.  You can see the differences by
applying "perl -MO=Concise".


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About