== Optimisation == Writing code which runs fast. Consider having configurations which are read from DB frequently but written-to rarely, be set in configuration files which are written-out from the DB (like the CSS from themes) * http://wiki.python.org/moin/PythonSpeed/PerformanceTips * http://www.python.org/doc/essays/list2str/ * http://www.skymind.com/~ocrow/python_string/ * http://diveintopython.org/performance_tuning/index.html * If a specific inner-loop routine canot be optimised in Python, then consider writing a C routine for this use case. === Specific Examples === NB These vary on cases, so use the Profiler to see how they work in your cases... {{{ for i in range(0, len(rows)): row = rows[i] }}} runs much faster than: {{{ for row in rows: }}} (0.05 vs. 0.001 seconds in one test case, 2x improvement in another & a slight negative improvement in a 3rd). ---- {{{ value = db(table.id==id).select(table.field, limitby=(0, 1))[0] }}} runs 1.5x faster than: {{{ value = table[id].field }}} (0.012 vs. 0.007 seconds vs in a test case) === Profiling === * Web2Py can [http://www.mail-archive.com/web2py@googlegroups.com/msg06267.html use cProfile]: * {{{web2py.py -F profiler.log}}} * or if running as service, edit {{{options.py}}}: {{{profiler_filename = 'profiler.log'}}} * http://docs.python.org/library/profile.html * http://www.cherrypy.org/wiki/Testing#Profiling * http://mg.pov.lt/profilehooks/ * YSlow plugin for Firebug: http://developer.yahoo.com/yslow/ ---- DeveloperGuidelines