| 1 | #!/usr/bin/env python
|
|---|
| 2 |
|
|---|
| 3 | """ systimes() user and system timer implementations for use by
|
|---|
| 4 | pybench.
|
|---|
| 5 |
|
|---|
| 6 | This module implements various different strategies for measuring
|
|---|
| 7 | performance timings. It tries to choose the best available method
|
|---|
| 8 | based on the platforma and available tools.
|
|---|
| 9 |
|
|---|
| 10 | On Windows, it is recommended to have the Mark Hammond win32
|
|---|
| 11 | package installed. Alternatively, the Thomas Heller ctypes
|
|---|
| 12 | packages can also be used.
|
|---|
| 13 |
|
|---|
| 14 | On Unix systems, the standard resource module provides the highest
|
|---|
| 15 | resolution timings. Unfortunately, it is not available on all Unix
|
|---|
| 16 | platforms.
|
|---|
| 17 |
|
|---|
| 18 | If no supported timing methods based on process time can be found,
|
|---|
| 19 | the module reverts to the highest resolution wall-clock timer
|
|---|
| 20 | instead. The system time part will then always be 0.0.
|
|---|
| 21 |
|
|---|
| 22 | The module exports one public API:
|
|---|
| 23 |
|
|---|
| 24 | def systimes():
|
|---|
| 25 |
|
|---|
| 26 | Return the current timer values for measuring user and system
|
|---|
| 27 | time as tuple of seconds (user_time, system_time).
|
|---|
| 28 |
|
|---|
| 29 | Copyright (c) 2006, Marc-Andre Lemburg ([email protected]). See the
|
|---|
| 30 | documentation for further information on copyrights, or contact
|
|---|
| 31 | the author. All Rights Reserved.
|
|---|
| 32 |
|
|---|
| 33 | """
|
|---|
| 34 | import time, sys, struct
|
|---|
| 35 |
|
|---|
| 36 | #
|
|---|
| 37 | # Note: Please keep this module compatible to Python 1.5.2.
|
|---|
| 38 | #
|
|---|
| 39 | # TODOs:
|
|---|
| 40 | #
|
|---|
| 41 | # * Add ctypes wrapper for new clock_gettime() real-time POSIX APIs;
|
|---|
| 42 | # these will then provide nano-second resolution where available.
|
|---|
| 43 | #
|
|---|
| 44 | # * Add a function that returns the resolution of systimes()
|
|---|
| 45 | # values, ie. systimesres().
|
|---|
| 46 | #
|
|---|
| 47 |
|
|---|
| 48 | ### Choose an implementation
|
|---|
| 49 |
|
|---|
| 50 | SYSTIMES_IMPLEMENTATION = None
|
|---|
| 51 | USE_CTYPES_GETPROCESSTIMES = 'cytpes GetProcessTimes() wrapper'
|
|---|
| 52 | USE_WIN32PROCESS_GETPROCESSTIMES = 'win32process.GetProcessTimes()'
|
|---|
| 53 | USE_RESOURCE_GETRUSAGE = 'resource.getrusage()'
|
|---|
|
|---|