Sample code for Profiler

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • psbasha
    Contributor
    • Feb 2007
    • 440

    Sample code for Profiler

    Hi,

    Could anybody help me in getting the Sample code ,how to use the Profiler in Python applications.


    Thanks in adavance
    PSB
  • Sushi
    New Member
    • Dec 2006
    • 18

    #2
    I couldnt help with your other questions but I thought I might try to help with this.

    I wasnt entirely sure what you meant but thought this website might help:
    http://www.onlamp.com/pub/a/python/2005/12/15/profiling.html

    or the page from the python library site:
    http://docs.python.org/lib/profile.html

    sorry if I completely misunderstood what you wanted!

    Comment

    • Arnold Schuur
      New Member
      • Apr 2007
      • 36

      #3
      This is a very basic example which demonstrates the python profiler:

      Code:
      import profile
      
      def counterTest():
          """Count from 1 to 100000 using the
          append instruction
          """
          Counter = []
          for i in range(100000):
                      Counter.append(i)
          return Counter
              
      print "Profile for counterTest, print the CPU time it took to count from 1 to 100000\n"
      profile.run('counterTest()')
      The output looks like:

      Profile for counterTest, print the CPU time it took to count from 1 to 100000

      100005 function calls in 1.226 CPU seconds

      Ordered by: standard name

      ncalls tottime percall cumtime percall filename:lineno (function)
      100000 0.549 0.000 0.549 0.000 :0(append)
      1 0.012 0.012 0.012 0.012 :0(range)
      1 0.000 0.000 0.000 0.000 :0(setprofile)
      1 0.009 0.009 1.225 1.225 <string>:1(?)
      1 0.656 0.656 1.216 1.216 prof_example.py :3(counterTest)
      1 0.000 0.000 1.226 1.226 profile:0(count erTest())
      0 0.000 0.000 profile:0(profi ler)

      Comment

      Working...