Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Why "Modern Perl" is slower than "Legacy Perl"?

by Tux (Canon)
on Jun 19, 2011 at 15:57 UTC ( [id://910444]=note: print w/replies, xml ) Need Help??


in reply to Why "Modern Perl" is slower than "Legacy Perl"?

I personally don't think that /^$/ is more perlish than eq "" is. Neither is a different layout or the use of single quotes versus the use of double quotes or the use of statement modifiers (action if expression) is better or more modern than (expression and action).

Modern perl offers more optimizer paths internally, and that is needed because there are so many ways to address a problem. The best way is the way than gets the job done in a manner that the whole team agrees with and is done in a way that the maintainer 5 years from now can still read. Squeezing out nanoseconds on statements that are only visited once in the lifecycle of a program is useless. If the statement however is visited millions of times it might be worthwhile to bench the effect. And the still, it might be only a vilid optimization on that local machine with that build of perl on that architecture.

I did try your test on the 85 perl builds I have available (all build with the same configuration) and I just noted that threaded perls all came in much slower than unthreaded perls.

rank elapsed cuser csys pass perl perl + rank ==== ========== ======= ======= ==== ================= ============== +=== ==== 1 0.00363 0.000 0.010 FAIL base/perl5.00504 /pro/bin/perl + 19 2 0.00912 0.000 0.000 FAIL base/perl5.00307 /usr/bin/perl + 34 3 0.02307 0.000 0.000 FAIL base/perl5.00503 base/perl5.003 +07 2 4 0.07953 0.000 0.010 FAIL base/perl5.00405 base/perl5.004 +05 4 5 2.61894 2.580 0.010 PASS base/perl5.6.2 base/perl5.005 +03 3 6 2.68016 2.630 0.020 PASS base/perl5.6.1 base/perl5.005 +04 1 7 2.68523 2.660 0.010 PASS base/perl5.6.0 base/perl5.6.0 + 7 8 2.83037 2.800 0.010 PASS base/perl5.8.0 base/perl5.6.1 + 6 9 2.88885 2.720 0.010 PASS base/perl5.8.3 base/tperl5.6. +1 12 10 2.91004 2.720 0.010 PASS base/perl5.8.2 base/perl5.6.2 + 5 11 2.91830 2.750 0.010 PASS base/perl5.8.7 base/tperl5.6. +2 18 12 2.92083 2.900 0.020 PASS base/tperl5.6.1 base/perl5.8.0 + 8 13 2.92413 2.750 0.010 PASS base/perl5.8.8 base/tperl5.8. +0 20 14 2.93176 2.720 0.010 PASS base/perl5.8.5 base/perl5.8.1 + 15 15 2.93800 2.730 0.020 PASS base/perl5.8.1 base/tperl5.8. +1 23 16 2.94319 2.740 0.010 PASS base/perl5.8.4 base/perl5.8.2 + 10 17 2.94600 2.690 0.010 PASS base/perl5.8.6 base/tperl5.8. +2 24 18 3.00963 2.990 0.010 PASS base/tperl5.6.2 base/perl5.8.3 + 9 19 3.06281 3.020 0.020 PASS /pro/bin/perl base/tperl5.8. +3 25 20 3.09148 3.070 0.020 PASS base/tperl5.8.0 base/perl5.8.4 + 16 21 3.10270 2.860 0.040 PASS base/perl5.8.9 base/tperl5.8. +4 27 22 3.17054 3.000 0.020 PASS base/tperl5.8.7 base/perl5.8.5 + 14 23 3.18847 3.010 0.010 PASS base/tperl5.8.1 base/tperl5.8. +5 28 24 3.20540 3.030 0.020 PASS base/tperl5.8.2 base/perl5.8.6 + 17 25 3.24457 3.070 0.000 PASS base/tperl5.8.3 base/tperl5.8. +6 30 26 3.29392 3.110 0.010 PASS base/tperl5.8.8 base/perl5.8.7 + 11 27 3.29553 3.080 0.010 PASS base/tperl5.8.4 base/tperl5.8. +7 22 28 3.30491 3.010 0.010 PASS base/tperl5.8.5 base/perl5.8.8 + 13 29 3.31124 3.030 0.070 PASS base/perl5.10.1 base/tperl5.8. +8 26 30 3.32899 3.090 0.010 PASS base/tperl5.8.6 base/perl5.8.9 + 21 31 3.43455 3.160 0.040 PASS base/perl5.10.0 base/tperl5.8. +9 46 32 3.43906 3.120 0.070 PASS base/perl5.12.0 base/perl5.10. +0 31 33 3.44477 3.110 0.060 PASS base/perl5.13.4 base/tperl5.10 +.0 55 34 3.52390 3.390 0.000 PASS /usr/bin/perl base/perl5.10. +1 29 35 3.52483 3.210 0.020 PASS base/perl5.13.8 base/tperl5.10 +.1 60 36 3.52753 3.250 0.030 PASS base/perl5.13.6 base/perl5.11. +0 52 37 3.54057 3.250 0.010 PASS base/perl5.13.5 base/tperl5.11 +.0 62 38 3.55223 3.320 0.010 PASS base/perl5.14.0 base/perl5.11. +1 56 39 3.55414 3.200 0.080 PASS base/perl5.11.2 base/tperl5.11 +.1 72 40 3.55444 3.120 0.070 PASS base/perl5.13.2 base/perl5.11. +2 39 41 3.57146 3.150 0.070 PASS base/perl5.13.1 base/tperl5.11 +.2 71 42 3.57274 3.260 0.100 PASS base/perl5.14.1 base/perl5.11. +3 51 43 3.59174 3.310 0.060 PASS base/perl5.13.11 base/tperl5.11 +.3 75 44 3.59178 3.200 0.090 PASS base/perl5.12.4 base/perl5.11. +4 45 45 3.59741 3.160 0.060 PASS base/perl5.11.4 base/tperl5.11 +.4 79 46 3.61302 3.240 0.060 PASS base/tperl5.8.9 base/perl5.11. +5 50 47 3.61401 3.300 0.010 PASS base/perl5.12.3 base/tperl5.11 +.5 64 48 3.63592 3.330 0.080 PASS base/perl5.13.10 base/perl5.12. +0 32 49 3.64948 3.290 0.010 PASS base/perl5.12.1 base/tperl5.12 +.0 73 50 3.65347 3.240 0.070 PASS base/perl5.11.5 base/perl5.12. +1 49 51 3.65606 3.220 0.070 PASS base/perl5.11.3 base/tperl5.12 +.1 65 52 3.69079 3.250 0.080 PASS base/perl5.11.0 base/perl5.12. +2 58 53 3.69301 3.260 0.070 PASS base/perl5.13.3 base/tperl5.12 +.2 84 54 3.71434 3.320 0.080 PASS base/perl5.13.9 base/perl5.12. +3 47 55 3.72287 3.460 0.070 PASS base/tperl5.10.0 base/tperl5.12 +.3 82 56 3.72652 3.270 0.090 PASS base/perl5.11.1 base/perl5.12. +4 44 57 3.73024 3.330 0.050 PASS base/perl5.13.7 base/tperl5.12 +.4 85 58 3.75741 3.280 0.090 PASS base/perl5.12.2 base/perl5.13. +0 59 59 3.77567 3.390 0.060 PASS base/perl5.13.0 base/tperl5.13 +.0 77 60 3.88845 3.640 0.000 PASS base/tperl5.10.1 base/perl5.13. +1 41 61 3.95350 3.700 0.050 PASS base/tperl5.13.10 base/tperl5.13 +.1 66 62 3.99173 3.630 0.060 PASS base/tperl5.11.0 base/perl5.13. +2 40 63 3.99887 3.720 0.080 PASS base/tperl5.14.0 base/tperl5.13 +.2 78 64 3.99972 3.690 0.070 PASS base/tperl5.11.5 base/perl5.13. +3 53 65 4.00705 3.730 0.010 PASS base/tperl5.12.1 base/tperl5.13 +.3 80 66 4.02853 3.710 0.080 PASS base/tperl5.13.1 base/perl5.13. +4 33 67 4.04036 3.740 0.020 PASS base/tperl5.13.6 base/tperl5.13 +.4 83 68 4.04658 3.740 0.020 PASS base/tperl5.13.5 base/perl5.13. +5 37 69 4.06868 3.820 0.010 PASS base/tperl5.13.9 base/tperl5.13 +.5 68 70 4.07103 3.870 0.040 PASS base/tperl5.13.11 base/perl5.13. +6 36 71 4.07516 3.700 0.100 PASS base/tperl5.11.2 base/tperl5.13 +.6 67 72 4.09376 3.760 0.060 PASS base/tperl5.11.1 base/perl5.13. +7 57 73 4.11930 3.790 0.030 PASS base/tperl5.12.0 base/tperl5.13 +.7 81 74 4.11944 3.870 0.010 PASS base/tperl5.14.1 base/perl5.13. +8 35 75 4.13039 3.800 0.050 PASS base/tperl5.11.3 base/tperl5.13 +.8 76 76 4.13756 3.750 0.060 PASS base/tperl5.13.8 base/perl5.13. +9 54 77 4.14126 3.860 0.030 PASS base/tperl5.13.0 base/tperl5.13 +.9 69 78 4.14612 3.740 0.070 PASS base/tperl5.13.2 base/perl5.13. +10 48 79 4.16076 3.830 0.080 PASS base/tperl5.11.4 base/tperl5.13 +.10 61 80 4.17469 3.690 0.080 PASS base/tperl5.13.3 base/perl5.13. +11 43 81 4.17835 3.720 0.120 PASS base/tperl5.13.7 base/tperl5.13 +.11 70 82 4.20535 3.820 0.090 PASS base/tperl5.12.3 base/perl5.14. +0 38 83 4.21454 3.880 0.080 PASS base/tperl5.13.4 base/tperl5.14 +.0 63 84 4.21915 3.780 0.100 PASS base/tperl5.12.2 base/perl5.14. +1 42 85 4.23053 3.860 0.010 PASS base/tperl5.12.4 base/tperl5.14 +.1 74

Another point in your post includes the work against databases. In my experience, the database is always slower than your perl script, so the gain of a few microseconds in using a syntax that you like/dislike is lost against milliseconds you loose with every database access.


Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^2: Why "Modern Perl" is slower than "Legacy Perl"?
by dwalin (Monk) on Jun 19, 2011 at 17:11 UTC
    Thanks for suggestions. My benchmarks shown here were rather synthetic; they were for illustrative purposes mostly. I don't usually try to optimize my scripts to the ground, but this case is very special for me. I won't go into detail but I really need to shave off all unnecessary code to save CPU cycles. For me, CPU utilization has always meant code speed and so I was trying to make my code faster so it could run cleaner with regards to CPU. I'm not fanatic about it and I won't rewrite it in C, that would give marginal results vs huge overhead; I consider it an exercise I can afford spending my time at while I'm waiting for the next project phase to begin. Besides, it looked like a perfect opportunity to acquaint myself with Devel::NYTProf, finally. :)

    I must tell that it was very educational for me this way; not only I learnt that newer Perl doesn't mean faster Perl - as your table would suggest, it's actually vice versa - but also I was never aware that speed and CPU utilization are not directly related. In fact, I have discovered it just now and I'm still trying to find an explanation to the fact that the same script ran with Perl 5.6.1 consumes ~4% CPU, but it goes up to ~6% with Perl 5.8.9 and even higher to ~8% with 5.14.1, as reported by prstat. But the test results suggest that it's faster with 8.9! Frankly, I'm at loss - the only explanation I can think up is that Perl 5.6.1 shipped with Solaris has some magic optimizations built in vs vanilla Perl. perl -V does state that it has 48 patches applied, but that doesn't explain the same 2% 5.14 adds over to 5.8. I need to dig up Solaris 10 DVD, set up another virtual machine and try it there - Sol10 ships with Perl 5.8 as standard. But it's black magic anyway.

    Regarding the database optimization, I fully agree with you. If it was any other database engine I would spend my time juggling SQL statements; in case of SQLite it's not so advanced and doesn't have a lot of options to play with. But it's not the case either because the problem was not in SQLite code itself which is highly optimized and blazingly fast, the problem was (and is) in DBD::SQLite that somehow runs twice slower when you use execute_array instead of execute. I tried to check if it was Perl issue instead, and discovered that not all Camels are created equal... It led me to this meditation.

    Regards,
    Alex.

Re^2: Why "Modern Perl" is slower than "Legacy Perl"?
by JavaFan (Canon) on Jul 03, 2011 at 20:54 UTC
    I just noted that threaded perls all came in much slower than unthreaded perls.
    You sound surprised. I'd gather from your years on p5p that you would know.

    For the rest of the world, it's a known fact that a perl build with thread support is significantly slower than a perl build without thread support (the ability to do threads is already enough for the slowdown - it's a price you pay regardless whether you actually use threads or not). This is why Perl by default (that is, after a ./Configure -d) is build without thread support.

      I'm not surprised that threaded perl builds are slower. I know. I also know that the impact is much less now in more recent perl builds that it was in older perl versions. I can see on a day-to-day basis what the impact is of threads vs non-threads in my smoke status. Today it shows threaded is 5.3% slower than non-threaded. Look at the bottom.

      I hereby would put the word "significantly" into a bit of a context. I still think that 5.3% is significant enough to not want a threaded perl build, as I NEVER ever saw the need for threads.

      With more and more (useful) perl applications actually using threads (e.g. Padre won't even run without them), I can see people wanting them. For me any app requiring threads is reason enough to not even try it.


      Enjoy, Have FUN! H.Merijn

        Threads make Win32 more bearable :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://910444]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-24 02:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found