blendenzo.com
News Tutorials Games Downloads Links Contact

Featured Author:
blendenzo!!
-blendenzo-

Tutorials - Blender Game Engine

Python vs. Logic Bricks

by blendenzo

There's a rumor that goes around in the BGE community that Python scripts are faster than Logic Bricks. This never made sense to me, since Logic Bricks are coded in C++, which is a lower level programming language than Python, meaning that (in theory) they should require slightly less processing time than Python scripts. Not being satisfied with my theories or the claims of others, I decided to do a simple test to see if Python is always faster than Logic Bricks. I set up two identical files, one using Logic Bricks, the other using Python. The two files are both laid out efficiently, and the Logic Bricks and Python are exact copies of each other functionally speaking.

The Test Files
LogicVersusPython.zip (57KB)

I ran both files multiple times and monitored the "Logic" percentage in the profile data. (Note: Since Python scripts run through a Logic Brick, their processor usage is lumped into the Logic percentage in the profile data.)

My Findings
In such a simple application as this, there is no noticeable speed difference between the two solutions. If anything, the Python solution is very slightly slower in general, though the Logic Brick solution is more likely to sporadically jump to a higher percentage.

Points of Interest
In deciding which solution to use, you may find these observations useful:
  1. The Python solution ran smoother and cleaner, with less sporadic jumps in processor usage.
  2. The Python solution added 11KB to overall file size compared the Logic Brick solution (Logic: 113KB, Python: 124KB).
  3. Sloppy usage of Logic Bricks can very easily produce a noticeably slower end result.
  4. It is more difficult to efficiently use Logic Bricks than it is to write efficient Python scripts.
The best overall solution seems to be to use Logic Bricks for simpler tasks and to use Python scripts for more complicated ones.

My Conclusion
While it may be true that Python is faster than Logic Bricks in some cases, the broad and sweeping claim that "Python is faster than Logic Bricks" cannot be supported in all cases, so it is (logically speaking) a false statement.

-blendenzo


Back to the tutorials index...


Website design by Tony "blendenzo" DiRienzo. All content © Copyright Tony DiRienzo unless otherwise noted.