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

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

Thread Next
From:
Glenn Golden
Date:
May 19, 2015 19:57
Subject:
Curiosity about "do {;}" vs. "{;}" realtime cost
Message ID:
20150519195726.GA8595@huh.zplane.com
While fiddling around with some empty blocks that had been used as placeholders,
happened to accidentally notice that "do {;}" and "{;}" have different realtime
costs. For example, with perl 5.20.1, on x86_64:

   for (my $i = 0; $i < 1e8; ++$i) {          }		# ET ~= 5s
   for (my $i = 0; $i < 1e8; ++$i) { do { ; } }		# ET ~= 5s
   for (my $i = 0; $i < 1e8; ++$i) {    { ; } }		# ET ~= 10s

I'd have guessed that both constructs would get optimized away during
compilation, but evidently "{;}" incurs some execution overhead that
"do {;}" does not.

This is not causing any difficulty whatsoever, nor am I suggesting that
anything is wrong or even peculiar about this; simply curious about why it is.


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About