home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / python / pyhtml / pyhtmldoc / p / profiler_e < prev    next >
Encoding:
Text File  |  1996-11-14  |  2.2 KB  |  42 lines

  1. <TITLE>Profiler Extensions -- Python library reference</TITLE>
  2. Prev: <A HREF="../c/calibration" TYPE="Prev">Calibration</A>  
  3. Up: <A HREF="../t/the_python_profiler" TYPE="Up">The Python Profiler</A>  
  4. Top: <A HREF="../t/top" TYPE="Top">Top</A>  
  5. <H1>9.8. Extensions --- Deriving Better Profilers</H1>
  6. The <CODE>Profile</CODE> class of module <CODE>profile</CODE> was written so that
  7. derived classes could be developed to extend the profiler.  Rather
  8. than describing all the details of such an effort, I'll just present
  9. the following two examples of derived classes that can be used to do
  10. profiling.  If the reader is an avid Python programmer, then it should
  11. be possible to use these as a model and create similar (and perchance
  12. better) profile classes.
  13. <P>
  14. If all you want to do is change how the timer is called, or which
  15. timer function is used, then the basic class has an option for that in
  16. the constructor for the class.  Consider passing the name of a
  17. function to call into the constructor:
  18. <P>
  19. <UL COMPACT><CODE>    pr = profile.Profile(your_time_func)<P>
  20. </CODE></UL>
  21. The resulting profiler will call <CODE>your_time_func()</CODE> instead of
  22. <CODE>os.times()</CODE>.  The function should return either a single number
  23. or a list of numbers (like what <CODE>os.times()</CODE> returns).  If the
  24. function returns a single time number, or the list of returned numbers
  25. has length 2, then you will get an especially fast version of the
  26. dispatch routine.
  27. <P>
  28. Be warned that you <I>should</I> calibrate the profiler class for the
  29. timer function that you choose.  For most machines, a timer that
  30. returns a lone integer value will provide the best results in terms of
  31. low overhead during profiling.  (os.times is <I>pretty</I> bad, 'cause
  32. it returns a tuple of floating point values, so all arithmetic is
  33. floating point in the profiler!).  If you want to substitute a
  34. better timer in the cleanest fashion, you should derive a class, and
  35. simply put in the replacement dispatch method that better handles your
  36. timer call, along with the appropriate calibration constant :-).
  37. <P>
  38. <H2>Menu</H2><DL COMPACT>
  39. <DT><A HREF="../o/oldprofile_class" TYPE=Menu>OldProfile Class</A>
  40. <DD><DT><A HREF="../h/hotprofile_class" TYPE=Menu>HotProfile Class</A>
  41. <DD></DL>
  42.