Monster's profiler - a class for profiling

Hi,

This is to check for bottlenecks in Python code.
The module Profiler provides some classes to check how long processing takes.

How to use:
create a Profiler instance (e.g. TimeProfiler).
give it a title to distinguish it from other Profiler outputs
give it a period - the Profiler will print its results after collecting this number of measures
stored it somewhere (e.g. at the object)
start measure before the code in question
end the measure after the code in question

Output example:


Blender Game Engine Started

complete time: profiled 100 measures - avg:0.011, min0.00410, max:0.018
complete time: profiled 100 measures - avg:0.010, min0.00402, max:0.017
complete time: profiled 100 measures - avg:0.010, min0.00398, max:0.017

Blender Game Engine Finished

You can have as much profilers as you want.

It runs in 2.49, 2.5 and 2.6

Attachments

ProfilerDemo.blend (38.7 KB)

Great resource.
A good idea is to plan your project to include something like this at the planning stage, as it can be difficult to check everything later.

I usually use import time,


import time
start = time.clock()

>>> (main part of script)

end = time.clock()

print ("script took %.2gs" % (end-start))


… to measure how long my scripts are taking when I’m first writing them. This lets me know if there’s something slowing it down, and what effect different events and properties have on the script processing time.
But having a dedicated class and some more statistics is great.

nice, didnt know about the own.get() Method. Sounds to be a good way to check instead of hasattr()… useful. I’ll integrate.