summaryrefslogtreecommitdiff
path: root/scripts/internal/bench_win_loadlib.py
blob: 61e2146fc1740d71b5a7d5753952d3256747670e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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()