Am I missing something?use Benchmark ;timethese (200, { 'if_cond_then_statement'=> sub { ;my $ris=0 ;for my $i (0..100000) { if (int ($i/2)>7) { $ris+=1 } } } ,'statement_if_cond'=> sub { ;my $ris=0 ;for my $i (0..100000) { $ris+=1 if int ($i/7)>0 } } }) Benchmark: timing 200 iterations of if_cond_then_statement, statement_ +if_cond...if_cond_then_statement: 61 wallclock secs (58.33 usr + 0.0 +3 sys = 58.36 CPU) @ 3.43/s (n=200) statement_if_cond: 60 wallclock secs (59.15 usr + 0.01 sys = 59.16 CP +U) @ 3.38/s (n=200)
In reply to Re: How Perl Optimize your code & some code TIPS ;-P
by slim
in thread How Perl Optimize your code & some code TIPS ;-P
by gmpassos
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |