Revolution, Python and bytecode optimization - A teeny math benchmark

Gordon gwalias-rev at yahoo.com
Tue Dec 7 11:33:30 EST 2004


Dear Revolutionaries

I really like Python and I was just curious to see how
the rev compiled bytecode compared to Python's in a
very simple math benchmark. I am definitely NOT making
any kind of statement here about Rev. or Python (or
any other programming language for that matter). If we
simply wanted to do pure math at lightning speeds and
cared little about wonderful interfaces or programming
flexibility, we'd all be using a command line C
compiler. 

That being said however, I am always interested in any
approach that can combine the wonderful flexibility of
4th generation languages with the performance
traditionally associated with the statically typed,
compiled languages (like C or Fortran). Of course,
languages like C will likely always have certain
advantages with regards to performance optimization,
compared with Rev or Python, but any tricks we can use
that can improve the performance of the languages we
love, can potentially give us the best of both worlds.

This is something the Python community has really
taken to heart. Successive releases of Python have
gotten ever faster (20 - 30% speed up between Python
2.2 and 2.3, another ~5% for Python 2.4) but it's the
Python community at large (arguably the lynchpin of
Python's success) that have really stepped up to the
plate and provided superb tools for improving Python's
performance. Python users can now inline C code with
modules like Pyrex and Weave and in an even simpler
approach, they can optimize the Python bytecode with
modules like Psyco, which can make a really dramatic
performance difference.

So as Marty DiBergi would say - enough of my yackin'
let's boogie!

Teeny math benchmark:
10,000,000 iterations of a loop, calculating the
square root of the loop index on each pass.

Revolution 2.5
  repeat with n = 1 to niter
    put sqrt(n) into tmp
  end repeat

Time = 7.133 seconds (elapsed)

Python 2.3
while n <= niter:
   s = math.sqrt(n)
   n += 1

Time = 18.1 seconds (elapsed)

Python 2.3 with Psyco bytecode optimization
One line of code added "psyco.bind(timeit)" where
"timeit" is the name of my simple iterative function

Time = 1.66 seconds (elapsed)

<big hand-waving disclaimer>
I know I know ... the author of this little benchmark
is fully aware that this is just one tiny aspect of
each langauge and that it doesn't prove anything and
you shouldn't sell the farm based upon this etc. etc.
... He was just curious and wanted to make the point
about bytecode optimization.
</big hand-waving disclaimer>


Questions:
Could such a bytecode optimization approach work for
compiled Rev stacks also? 

Are there other people out there thinking about such
things as how to add C modules for computationally
intensive parts of a Rev. program? 

Is the Rev. externals package easy enough to use that
it constitutes a viable solution to improving
perfomance through the use of DLLs?

Best

Gordon

=====
:::::::::: Gordon Webster ::::::::::


More information about the use-livecode mailing list