Eccentric Developments

Raybench - Python (PLC pt.7)

With 25 years in development, Python has been evolving from a hobby project to a full blown general purpose language used for scripting, data science, games programming, web servers and more.

For it's characteristics, Python is a imperative and dynamic language with some characteristics from functional programming included; also supporting the object oriented paradigm. It's main selling point is it's readable syntax, that uses indentation to delimit code blocks.


Python 2.7.6 was used for the tests.

Loading time

How fast does the interpreter loads and parses the source code.

$ time python 

real    0m0.052s
user    0m0.040s
sys     0m0.000s

Running Time

$ time python 

real    348m35.965s
user    345m51.776s
sys     0m22.880s
$ time pypy

real    14m2.406s
user    13m55.292s
sys     0m1.416s

The running time for the regular Python interpreter is abysmal, although not as bad as Lua. It gets much better if you are using Pypy, which makes the code run almost as fast as mono.

Code Metrics

Line count: 213 code, 57 blanks, 270 total. File size: 5825 bytes.

General Thoughts

I ran into several problems while doing the translation of the raybench source to Python, one of the main drawbacks was the way code blocks are defined using indentation. Personally it made the code blocks a bit more difficult to manage while not adding much to readability, also, I had to fight with vim's auto indentation which more often than not, inserted and incorrect amount of spaces for new lines, miss interpreting the context.

Another problem that was sort of difficult to debug was with the way divisions are handled. For instance, when dividing 5/4 in Lua or Javascript, the answer is 1.25, but the same operation in Python returns 1. Returning an integer from the division of two whole numbers is the expected behaviour of languages like C, where if you want a floating point result you have to cast one of the numbers to float or have the variables be of that type, but in Python there are no types, which makes this a bit more annoying. In any case, you have to add a decimal point to the dividend or the divisor, or you will loose the decimal digits.

On the bright side, Python has great support from libraries for almost any task imaginable, and runs on a great number of different platforms. Also, Pypy is awesomely fast!.


You can follow the development of this project on GitHub:

Enrique CR - 2016-06-11