in reply to use constant and Compiler Optimizations
Your example uses extremely fast constructs; the difference between doing a single multiplication and one "no-op" vs doing two multiplications (while still doing a relatively expensive function call each iteration for both constructs) is not very informative or useful.
Update: as an aside, a really hard-core optimizer would eliminate ALL of the code in these examples.use strict; use warnings; use Benchmark qw( cmpthese ); use constant DEBUG => 0; my $debug = 0; my $b = 100; cmpthese -10, { constant => sub { my $a = 10 * $b; $a = 10 * $b if DEBUG; }, noconstant => sub { my $a = 10 * $b; }, var => sub { my $a = 10 * $b; $a = 10 * $b if $debug; }, };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: use constant and Compiler Optimizations
by ikegami (Patriarch) on Jul 18, 2008 at 20:16 UTC | |
by Joost (Canon) on Jul 18, 2008 at 20:43 UTC | |
by BrowserUk (Patriarch) on Jul 18, 2008 at 22:26 UTC |