[Python-checkins] r46505 - python/trunk/Tools/pybench/systimes.py

Tim Peters tim.peters at gmail.com
Fri Jun 2 03:31:48 CEST 2006


> Author: marc-andre.lemburg
> Date: Sun May 28 19:46:58 2006
> New Revision: 46505
>
> Added:
>    python/trunk/Tools/pybench/systimes.py   (contents, props changed)

...

> +def win32process_getprocesstimes_systimes():
> +    d = win32process.GetProcessTimes(win32process.GetCurrentProcess())
> +    # Note: I'm not sure whether KernelTime on Windows is the same as
> +    # system time on Unix - I've yet to see a non-zero value for
> +    # KernelTime on Windows.
> +    return (d['UserTime'] / WIN32_PROCESS_TIMES_TICKS_PER_SECOND,
> +            d['KernelTime'] / WIN32_PROCESS_TIMES_TICKS_PER_SECOND)

FYI, I always see a non-zero, and increasing, value for KernelTime on
my box (WinXP Pro SP2).

Alas, these counters appear to have even worse resolution than
time.time() on my box, incrementing a seemingly variable(!) number of
times per second, but well under 100Hz:

"""
import win32process

def scream():
    from time import clock as now
    p = win32process.GetCurrentProcess()
    d = {}
    count = 0
    start = now()
    deadline = start + 1.0
    while now() < deadline:
        count += 1
        x = win32process.GetProcessTimes(p)
        d[x['UserTime']] = 1
    elapsed = now() - start
    print "saw", len(d), "distinct values in", \
          count, "tries across", elapsed, "seconds"
    print "user", x['UserTime'], "kernel", x['KernelTime']
    print

scream()
scream()
scream()
"""

One run of that here:

saw 74 distinct values in 134542 tries across 1.00000616787 seconds
user 11562500 kernel 2187500

saw 81 distinct values in 133365 tries across 1.00000220027 seconds
user 24062500 kernel 2968750

saw 68 distinct values in 132984 tries across 1.0000078902 seconds
user 34531250 kernel 4687500


More information about the Python-checkins mailing list