D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] Luke warm defence of Python? Web MVC framework I mentioned to Gordon

 

On Sun, 13 May 2012, Simon Waters wrote:

Gordon mentioned Python performance, but a quick sniff around confirms
that Python performance is typical of it's class of languages, and
broadly comparable to Ruby, and Perl. PHP which is slow within it's
class hasn't had it's adoption harmed by being (or a myriad of other
issues one might expect). Maybe Gordon's Basic interpreter is just
quick, I'm assuming RTB provides a nice simple clean Basic like I was
use to in the 1980s and thus probably all fits in the CPU cache, and
doesn't do anything embarrassingly complicated like many modern
languages do.

I did one benchmark to compare Python against RTB - and Python won. It's something called the Ackermann function - it's really a stress test for function recursion. I suspect that as Python is compiled "properly" into some byte-code that's then optimised and interpreted that then makes a good difference. My BASIC is tokenised into somewaht sub-optimal 16-bit token, however I also do stuff like build up a symbol table of variables, turn constants into binary numbers (stored in the symbol table) so the run-time part isn't that innefficient, but it could also be better. The list command is technically a de-compiler!

PHP was slower for the same function - quite a bit slower, so but recursion is something that can make or break any language... There are lots of other things that make PHP slow too - all arrays are associative, so there's an overhead there...

Ackermann in Python (the only Python program I've written!)

import resource
import sys

# Increase max stack size from 8MB to 512MB
resource.setrlimit(resource.RLIMIT_STACK, (2**29,-1))
sys.setrecursionlimit(10**6)


def ack1(M, N):
   return (N + 1) if M == 0 else (
      ack1(M-1, 1) if N == 0 else ack1(M-1, ack1(M, N-1)))


for x in xrange(0,4):
    for y in xrange(0,8):
      print ack1(x,y)

and in RTB:

PRINT "Start"
NUMFORMAT (5, 0)
start = TIME
FOR y = 0 TO 3 CYCLE
  FOR x = 0 TO 7 CYCLE
    z = FN ackermann(y, x)
    PRINT z;  " ";
  REPEAT
  PRINT
REPEAT
NUMFORMAT (5, 3)
PRINT "Done in ";  (TIME - start) / 1000;  " seconds."
END
//
DEF FN ackermann(m, n)
IF m = 0 THEN  = n + 1
IF n = 0 THEN  = FN ackermann(m - 1, 1)
 = FN ackermann(m - 1, FN ackermann(m, n - 1))


That of course brings me to the key point, that technical excellence is
no predictor of adoption. The Raspberry PI may be a good example as we
all spent a long time discussing the capabilities of a system whose key
feature is its cheapness, when the camera I took to the meeting is
probably a more powerful computer in many regards (and comes with a lot
more storage!).

And more built-in digital processing algorithms - probably faster too!

As for Python for system programming - if that's what people want, then so be it. Personally I feel that if it can't be done in shell scripts & awk, then maybe you shouldn't be inventing yet another language for it. So now we're seeing Linux installs that need Perl and Python just to boot. What overload & bloat.

Gordon

--
The Mailing List for the Devon & Cornwall LUG
http://mailman.dclug.org.uk/listinfo/list
FAQ: http://www.dcglug.org.uk/listfaq