Search code examples
pythonperformanceweb-applicationsinstrumentationmeasurement

Measuring performance in Python


I'm writing a web-application in Python, I haven't decided if I want to use Flask, web.py or something else yet, and I want to be able to do profile on the live application.

There seems to be very little information on how you go about implementing the instrumentation to do performance measurement, short of doing a lot of print datetime.now() everywhere.

What is the best way of going about instrumenting your Python application to allow good measurements to be made. I guess I'm looking for something similar to the Stackoverflow teams mvc-mini-profiler.


Solution

  • You could simply run cProfile tool that comes with Python:

    python -m cProfile script.py
    

    Of course, you would have to create the script.py file that would execute the parts of the code that you want to test. If you had some unit tests, you could also use that.

    Or you couse use:

    import cProfile 
    cProfile.run('foo()')
    

    to profile it from foo entry point.