in reply to Re: How Perl Optimize your code & some code TIPS ;-P
in thread How Perl Optimize your code & some code TIPS ;-P
For one thing, you have different conditions. In the first you use if (int ($i/2)>7) and in the second you use if int ($i/7)>0. In this case, it won't make too much difference (the latter will execute the conditional code a couple more times) but if you want meaningful results from a benchmark, make sure all implementations under consideration do the same thing.
On my system, if_cond_then_statement repeatedly beats out statement_if_cond with your original code and with it fixed using either of the if conditions above. The results are closer when both routines use the same if condition.
Also, it is convention to put the semicolon (;) at the end of the line containing the instruction it terminates, not at the beginning of the next line. It makes for much more readable code.
--- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';
|
---|