diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2019-02-20 09:38:21 -0800 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2019-02-20 09:38:21 -0800 |
commit | fd690d477b7d520f05d9cf7824334c5bc2fc671e (patch) | |
tree | 96f89cae5cd94bd31c90e6864561d0cc64327990 | |
parent | b46ec41a5cf3d9638fc33f16b00f235859371940 (diff) | |
download | psutil-fd690d477b7d520f05d9cf7824334c5bc2fc671e.tar.gz |
add benchmark script
-rw-r--r-- | scripts/internal/bench_win_loadlib.py | 49 | ||||
-rwxr-xr-x | scripts/internal/winmake.py | 7 |
2 files changed, 56 insertions, 0 deletions
diff --git a/scripts/internal/bench_win_loadlib.py b/scripts/internal/bench_win_loadlib.py new file mode 100644 index 00000000..61e2146f --- /dev/null +++ b/scripts/internal/bench_win_loadlib.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python + +# Copyright (c) 2009, Giampaolo Rodola'. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +""" +A simple micro benchmark script which tests the speedup introduced in: +https://github.com/giampaolo/psutil/pull/1422/ +""" + +from __future__ import print_function +import sys +import timeit + +import psutil + + +ITERATIONS = 10000 +apis = [ + 'psutil.boot_time()', + 'psutil.disk_io_counters()', + 'psutil.cpu_count(logical=False)', + 'psutil.cpu_count(logical=True)', + 'psutil.cpu_times(percpu=True)', + 'psutil.users()', + 'psutil.cpu_stats()', + # 'psutil.net_connections(kind="inet4")', # slow + 'proc.ionice()', + 'proc.ionice(0)', + # 'proc.open_files()', # slow + 'proc.cmdline()', + 'proc.cwd()', + # 'proc.environ()', # slow +] +apis = sorted(set(apis)) +setup = "import psutil; proc = psutil.Process()" + + +def main(): + if not psutil.WINDOWS: + sys.exit("Windows only") + for api in apis: + elapsed = timeit.timeit(api, setup=setup, number=ITERATIONS) + print("%-40s %.3f" % (api, elapsed)) + + +if __name__ == '__main__': + main() diff --git a/scripts/internal/winmake.py b/scripts/internal/winmake.py index b1ce7b8a..7edae55f 100755 --- a/scripts/internal/winmake.py +++ b/scripts/internal/winmake.py @@ -483,6 +483,13 @@ def bench_oneshot_2(): sh("%s -Wa scripts\\internal\\bench_oneshot_2.py" % PYTHON) +@cmd +def bench_loadlib(): + """Benchmarks for oneshot() ctx manager (see #1422).""" + install() + sh("%s -Wa scripts\\internal\\bench_win_loadlib.py" % PYTHON) + + def set_python(s): global PYTHON if os.path.isabs(s): |